1
疯狂的小圆圈
当按下鼠标左键滑动时,会产生一些列同心圆,这些同心圆运动,碰到四周会反弹。
这里要学习下字典。
2漂亮的彩虹
import pgzrunWIDTH = 800HEIGHT = 400def draw(): screen.fill('white') screen.draw.filled_circle((400, 400), 400, 'red') screen.draw.filled_circle((400, 400), 370, 'orange') screen.draw.filled_circle((400, 400), 340, 'yellow') screen.draw.filled_circle((400, 400), 310, 'green') screen.draw.filled_circle((400, 400), 280, 'blue') screen.draw.filled_circle((400, 400), 250, 'cyan') screen.draw.filled_circle((400, 400), 220, 'purple') screen.draw.filled_circle((400, 400), 190, 'white')pgzrun.go()
字典
colors = ['red', 'orange', 'yellow', 'green', 'blue', 'cyan', 'purple']col = colors[0]print(col)col = colors[6]print(col)
第1行:定义一个字典,里面存储了7个颜色
第3行:打印字典中第一个元素
第5行:打印字典中最后一个元素
字典还有许多操作,追加、遍历等等
4一个弹跳的小球