from kandinsky import * import time import random NUM_ROWS, NUM_COLS, NUM_FLAKES = 27, 40, 50 SNOWFLAKES = "#*+." SLEEP_TIME = 0.1 WIND_PROBABILITY = 0.1 BG, WH = (20,60,100), (255,)*3 class Snowflake: def __init__(self): self.char = random.choice(SNOWFLAKES) self.x = random.randint(0, NUM_COLS - 1) self.y = random.randint(-NUM_ROWS, 0) self.sway = random.choice([-1, 0, 1]) def move(self, wind): self.y += 1 self.x += self.sway + wind if self.x < 0: self.x = NUM_COLS - 1 elif self.x >= NUM_COLS: self.x = 0 def main(): flakes = [Snowflake() for _ in range(NUM_FLAKES)] wind = 0 rvb = [0, 0, 0] while True: fill_rect(0, 0, 320, 222, BG) for i in range(3) : rvb[i] = (rvb[i] + (i + 1) * random.randint(0,4)) % 255 if random.random() < WIND_PROBABILITY: wind = random.choice([-1, 0, 1]) for flake in flakes: flake.move(wind) if flake.y < NUM_ROWS: draw_string(flake.char, 8*flake.x, 8*flake.y,WH,BG) else: flake.y = random.randint(-NUM_ROWS, 0) flake.x = random.randint(0, NUM_COLS - 1) coul = BG if sum(rvb) > 300 else WH draw_string("J O Y E U S E S F E T E S", 30, 110, coul, rvb) time.sleep(SLEEP_TIME) main()