bf24.py

Created by schraf

Created on December 19, 2024

1.35 KB


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()

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.