# List of Ball objects D = draw.Drawing(200, 200, origin='center') # define drawing canvas EARTH_GRAVITY_ACCELERATION = -9.8 # acceleration due to gravity, m/sec^2 BALL_RADIUS = 10 # radius of the ball in pixels ball_list = [] colors = ['red', 'orange', 'yellow','green', 'blue', 'indigo', 'violet'] for i in range(1,100): x = randint(-90,90) y = randint(-90,90) vx = 20*random() - 10 vy = 20*random() - 10 c = randint(0,len(colors)-1) ball_list.append( Ball( x, y, vx, vy, colors[c] ) ) def draw_frame(): for b in ball_list: b.draw_ball() for b in ball_list: b.update_position(0.1) # no gravity return D for i in range(0,1000): D = draw.Drawing(200, 200, origin='center') # erase canvas with draw.animate_jupyter(draw_frame, delay=0.05) as anim: anim.draw_frame() # List of Ball objects (with gravity) D = draw.Drawing(200, 200, origin='center') # define drawing canvas EARTH_GRAVITY_ACCELERATION = -9.8 # acceleration due to gravity, m/sec^2 BALL_RADIUS = 10 # radius of the ball in pixels def draw_frame(): for b in ball_list: b.draw_ball(); for b in ball_list: #b.update_position(0.2) # no gravity b.animate_step(0.2) # with gravity return D ball_list = []; # initialize empty list colors = ['red', 'orange', 'yellow','green', 'blue', 'indigo', 'violet'] for i in range(1,100): x = randint(-90,90) y = randint(-90,90) vx = 20*random() - 10 vy = 20*random() - 10 c = randint(0,len(colors)-1) ball_list.append( Ball(x, y, vx, vy, colors[c]) ) for i in range(0,1000): D = draw.Drawing(200, 200, origin='center' ) # erase canvas with draw.animate_jupyter(draw_frame, delay=0.05) as anim: anim.draw_frame()