# 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()

最新文章

  1. MR跑百分27不动引发的问题
  2. 用过sessionid防钓鱼
  3. C# DataGridViewComboBoxColumn 数据绑定
  4. 升级web项目步骤
  5. error C2504: “CActiveXDocControl”: 基类没有定义
  6. Linq实现对XML的简单增删查改
  7. SpringMVC 3.2集成Spring Security 3.2集成mybaties
  8. rownum基本用法
  9. poj - 1185 炮兵阵地 状压DP 解题报告
  10. hdu-2683 TCE-frep number system---完全数+二项展开式
  11. expdp/impdp数据泵分区表导入太慢了。添加不检查元数据参数提高效率:ACCESS_METHOD=DIRECT_PATH
  12. Java中CardLayout布局方式的应用
  13. bower install的时候报错
  14. English trip EM2-LP-3A Gifts Teacher:Patrick
  15. windows下MySQL的安装(非安装包)
  16. 设置 cookie过期时间
  17. Office WORD如何设置表格背景颜色
  18. 【Android】6.2 AlertDialog(警告对话框)
  19. 中小型园区网络的基本部署之动手划分vlan
  20. CountDownLatch CyclicBarrier Semaphore 比较

热门文章

  1. 多线程笔记--原子操作Interlocked系列函数
  2. oracle复制表数据,复制表结构
  3. 帝国cms数据表详细说明
  4. Qt的目录依赖问题----怎样生成一个绿色的Qt软件包
  5. mfc删除标题和边框
  6. Node安装及搭建简单服务器
  7. EJB3.0开发环境的搭建
  8. [Asp.net]常见word,excel,ppt,pdf在线预览方案(转)
  9. C#编辑基础笔记
  10. Codeforces 492B B. Vanya and Lanterns