您的位置:首页 > 其它

week4_motion_of_ball_1(小球运动)——改进

2014-10-18 10:53 309 查看
# Ball motion with an explicit timer
import simplegui

# Initialize globals
width = 600
height = 600
ball_pos = [width/2, height/2]
ball_radius = 20
ball_vel = [0, 1.0]#(pixels per 1/60seconds)

# define event handlers

def draw(canvas):
global ball_pos, ball_vel

# calculate ball position,use p(t+1) =  p(t) + v(t)
ball_pos[0] = ball_pos[0] + ball_vel[0]
ball_pos[1] = ball_pos[1] + ball_vel[1]

# draw ball
canvas.draw_circle(ball_pos, ball_radius, 6, 'white')

# create frame
frame = simplegui.create_frame('ball_motion', 600, 600)

# register event handlers
frame.set_draw_handler(draw)
# start frame
frame.start()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: