xmas2022.py

Created by schraf

Created on December 19, 2022

1.39 KB

Ma playlist consacrée à la NUMWORKS


import turtle
from math import *
from kandinsky import *
from random import choice, random
from time import sleep

fill_rect(0,0,320,222,(0,0,0))
nmax, xs, ys, zs = 60, 1, 2.8, 1.3
startFrom, dz = 0, 400

def getX(i, z, sign): return int(160+sign * i * cos(i) * z * xs)
def getY(i, z): return int(10+i * z * ys)

class spirale:
    def __init__(self,fg, bg, isLeft, yloc):
     self.sign = -2 * isLeft + 1
     self.yloc = yloc if yloc > 0 else 1
     if isLeft:
         (self.bg, self.fg) = (bg, fg)  
     else:
         (self.bg, self.fg) = (fg, bg)
    def show(self, i, h):
        zoff = i * sin(i)
        z = dz / (dz - self.sign * zoff * zs)
        x = getX(i, z, self.sign)
        y = getY(i * self.yloc + h * cos(800*i) , z) 
        c = self.fg if zoff + self.sign * pi / 4 < 0 else self.bg
        if sum(get_pixel(x,y)) == 0 or h == 1:
          s = 1 + int(3 * i) % 2
          fill_rect(x, y, s, s, c)

def aff(spiral, h = 0):
  i = -startFrom
  while i < nmax + startFrom:
    if i >= 0 and i <= nmax: spiral.show(i, h)
    i += 0.08

rouge = spirale((255,0,0), (68,0,0), True, 1)
cyan = spirale((0,255,204), (0, 86, 51), False, 1)

for v in rouge,cyan: aff(v)
while True:
    rvb = choice([(1,1,0),(0,1,1),(0,1,0),(0,0,1),(1,0,1)])
    c1 = tuple(255 * rvb[i] for i in rvb)
    c2 = tuple(70 * rvb[i] for i in rvb)
    decos = spirale(c1, c2, True, 1)
    aff(decos, 1)
    sleep(random())

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 <a href="https://www.numworks.com/legal/cookies-policy/">cookies policy</a>.