Melting Paradox
![]()
9C: Do problem 9A, this time with an interactive display of the difference in display area.
#
import math
import sys
def stream2 (y1):
for a in range (0, 200):
y = 200-a-y1
x1= 200-(int(a/2*math.sin(math.pi/30*a))+y)
x2 = 200-(int(a/2*math.sin(math.pi/30*a))+y)+int(a/2)
x3= 200-(int(a/2*math.sin(math.pi/30*a))+y)+int(a/3)
g.setPixel(x1+1, y, 100)
g.setPixel(x2, y, 100)
g.setPixel(x3, y, 100)
g.pause(1)
for a in range (0, 200):
y = 200-a-y1
x1= 200-(int(a/2*math.sin(math.pi/30*a))+y)
x2 = 200-(int(a/2*math.sin(math.pi/30*a))+y)+int(a/2)
x3= 200-(int(a/2*math.sin(math.pi/30*a))+y)+int(a/3)
g.setPixel(x1+1, y, 0)
g.setPixel(x2, y, 0)
g.setPixel(x3, y, 0)
g.pause(1)
def mountains():
g.line(76, 200, 0, 114)
for a in range (76, 200):
x = a
y = 200-abs((int(a/3*math.cos(math.pi/50*a))))
g.setPixel(x, y, 100)
mountains ()
def snow (x1, x2, y1, color):
for a in range(x1, x2):
x=a
y=y1-abs((int(8*math.cos(math.pi/14*a))))
g.setPixel(x, y, color)
def snowmelt():
snow(56, 88, 185,0)
snow (112, 134, 180,0)
snow (160, 191, 160,0)
snow(66,86,190,100)
snow(117,132,187,100)
snow(165,185,175,100)
g.pause(25)
snow(66,86,190,0)
snow(117,132,187,0)
snow(165,185,175,0)
snow(67,80,195, 100)
snow(122,129,194, 100)
snow(170,180,190,100)
g.pause(25)
snow(67,80,195, 0)
snow(122,129,194, 0)
snow(170,180,190,0)
snow(56, 88, 185,100)
snow (112, 134, 180,100)
snow (160, 191, 160,100)
def clickSnow2(x,y):
if x>=112:
if x<=134:
if y>(180-abs((int(8*math.cos(math.pi/14*x))))):
if y<(200-abs((int(x/3*math.cos(math.pi/50*x))))):
return 100
return 0
def clickSnow1(x,y):
if x>=56:
if x<=88:
if y>(180-abs((int(8*math.cos(math.pi/14*x))))):
if y<(200-abs((int(x/3*math.cos(math.pi/50*x))))):
return 100
return 0
def clickSnow3(x,y):
if x>=160:
if x<=191:
if y>(180-abs((int(8*math.cos(math.pi/14*x))))):
if y<(200-abs((int(x/3*math.cos(math.pi/50*x))))):
return 100
return 0
def isSnow():
while 1:
x=g.getMouse(1)
y=g.getMouse(2)
if clickSnow2(x, y)==100:
snowmelt()
stream2 ( 40)
return 0
if clickSnow1(x, y)==100:
snowmelt()
stream2 ( 40)
return 0
if clickSnow3(x, y)==100:
snowmelt()
stream2 ( 40)
return 0
isSnow()