zoukankan      html  css  js  c++  java
  • week4_motion_of_ball_1(小球运动)——改进

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

  • 相关阅读:
    4.26上午
    4.25下午
    4.19上午
    4.18上午
    7.26
    7.25
    7.21-7.22
    7.22
    7.21
    7.11-7.15
  • 原文地址:https://www.cnblogs.com/zhurun/p/4590547.html
Copyright © 2011-2022 走看看