from __future__ import division, print_function from visual import * from time import sleep # use "subprocess" instead of "thread" on python 3 from thread import start_new_thread from random import * def fall_ball(gravity, color, pos=(0, 5, 0)): our_ball = sphere(pos=pos, color=color) our_ball.pos = pos v_ball = 0 while True: while our_ball.pos[1] > -5: sleep(0.02) our_ball.pos[1] -= v_ball v_ball += gravity v_ball = -v_ball our_ball.pos[1] -= v_ball display(background=(1, 1, 1)) box(pos=(0, -5, 0), height=1, length=40, width=40) # Constant speed! Physics doesn't recommend that #for height in range(500, -500, -1): # sleep(.002) # our_ball.pos = (0, height/100, 0) for bnum in range(3000): sleep(random()) start_new_thread(fall_ball, (0.01 + random()/100, (random(), random(), random()), ((0.5-random())*30, 5, (0.5-random())*30))) if bnum%100 == 0: print(bnum) fall_ball(0.012, (1, 0, 0))