import simple_draw as sd
MAX_X = 1300
MAX_Y = 800
sd.resolution = (MAX_X, MAX_Y)
number_flakes = 100
flakes_list = []
class Snowflake:
def __init__(self, x, y):
self.x = x
self.y = y
self.speed = sd.random_number(10, 20)
self.length = sd.random_number(10, 41)
self.color = sd.COLOR_WHITE
def clear_previous_picture(self):
sd.start_drawing()
self.color = sd.background_color
sd.snowflake(center=sd.get_point(self.x, self.y),
length=self.length, color=self.color)
sd.finish_drawing()
def move(self):
self.y -= self.speed
if self.y > MAX_Y:
self.y = 40
self.x = sd.random_number(-5, 5)
def draw(self):
sd.start_drawing()
self.color = sd.COLOR_WHITE
sd.snowflake(center=sd.get_point(self.x, self.y),
length=self.length, color=self.color)
sd.finish_drawing()
def initialize(flakes_list, number_flakes):
for i in range(number_flakes):
xx = sd.random_number(0, 1250)
yy = sd.random_number(750, 800)
flakes_list.append(Snowflake(xx, yy))
initialize(flakes_list, number_flakes)
while True:
for flake in flakes_list:
flake.clear_previous_picture()
flake.move()
flake.draw()
sd.sleep(0.1)
if sd.user_want_exit():
break
sd.pause()