弹跳的小球(bouncingball.py)

 1 import stddraw
 2 
 3 stddraw.setXscale(-1, 1)
 4 stddraw.setYscale(-1, 1)
 5 
 6 DT = 20.0
 7 RADIUS = 0.05
 8 rx = 0.480
 9 ry = 0.860
10 vx = 0.015
11 vy = 0.023
12 while True:
13     #Update ball position and draw it there.
14     if abs(rx + vx) + RADIUS > 1.0:
15         vx = -vx
16     if abs(ry + vy) + RADIUS > 1.0:
17         vy = -vy
18     rx = rx + vx
19     ry = ry + vy
20     stddraw.clear(stddraw.GRAY)
21     stddraw.filledCircle(rx, ry, RADIUS)
22     stddraw.show(DT)

 

posted @ 2017-08-03 23:25  跳过了E  阅读(344)  评论(0)    收藏  举报