Bounce

#bounce
#the size and path of the ball depends on the position of the mouse
#right before the ball begins
g.norefresh()
import math
def distance (a,b,c,d):
return math.sqrt(pow(c-a, 2)+pow(d-b, 2))
def fillCircle (x, y, d,c):
for i in range (x, x+d):
for j in range (y, y+d):
if distance (i, j, (x+(d/2)), (y+(d/2))) < (d/2):
g.setPixel(i,j, c)
#a=amplitude, b=# of bounces, h = height
def bounce (a, n, h, r):
n=100/n
for x in range (0, 100):
y=int(abs(a*math.sin(math.pi/n*x))+h)
fillCircle(x,y, r, 100)
g.refresh()
g.pause(3)
g.paper(0)
bounce(60, 3, 40, 20)
while 1:
bounce(g.getMouse(2), (int(g.getMouse(2))%4 +2), g.getMouse(1), (g.getMouse(1)%5+1)*5)