week4_motion_of_ball_1(小球运动)——最基本
2024-09-01 13:15:20
# Ball motion with an explicit timer
import simplegui # Initialize globals
width = 600
height = 600
ball_pos_init = [width/2, height/2]
ball_radius = 20
ball_vel = [1, 1]
t = 0
# define event handlers def draw(canvas):
global ball_pos, ball_vel
ball_pos = [0, 0]
# calculate ball position, 所用p(t+1) = p(0) + (t+1)*v,每0.1s移动一个像素pixels
ball_pos[0] = ball_pos_init[0] + t * ball_vel[0]
ball_pos[1] = ball_pos_init[1] + t * ball_vel[1] # draw ball
canvas.draw_circle(ball_pos, ball_radius, 6, 'white')
def tick():
global t
t = t + 1
# create frame
frame = simplegui.create_frame('ball_motion', 600, 600)
timer = simplegui.create_timer(100,tick)
# register event handlers
frame.set_draw_handler(draw)
# start frame
frame.start()
timer.start()
rt()
最新文章
- MR跑百分27不动引发的问题
- 用过sessionid防钓鱼
- C# DataGridViewComboBoxColumn 数据绑定
- 升级web项目步骤
- error C2504: “CActiveXDocControl”: 基类没有定义
- Linq实现对XML的简单增删查改
- SpringMVC 3.2集成Spring Security 3.2集成mybaties
- rownum基本用法
- poj - 1185 炮兵阵地 状压DP 解题报告
- hdu-2683 TCE-frep number system---完全数+二项展开式
- expdp/impdp数据泵分区表导入太慢了。添加不检查元数据参数提高效率:ACCESS_METHOD=DIRECT_PATH
- Java中CardLayout布局方式的应用
- bower install的时候报错
- English trip EM2-LP-3A Gifts Teacher:Patrick
- windows下MySQL的安装(非安装包)
- 设置 cookie过期时间
- Office WORD如何设置表格背景颜色
- 【Android】6.2 AlertDialog(警告对话框)
- 中小型园区网络的基本部署之动手划分vlan
- CountDownLatch CyclicBarrier Semaphore 比较