cadeau.py

Created by elodie-gamot

Created on October 29, 2021

1.42 KB

Cadeau de Noël avec Kandinsky : cadeau() Avec en plus la neige qui tombe avec Time : tout()


from kandinsky import *
from math import *
from time import *
from random import *

white=color(255,255,255)
red=color(230,0,0)
green=color(0,230,0)
grey=color(60,60,80)
white=color(240,240,240)

def background():
  fill_rect(0,0,320,222,grey)
  
def ecriture():
  draw_string("Joyeux",200,100,red,grey)
  draw_string("Noel !",210,140,red,grey)

def ellipse(u,v,a,b,theta,color):
  d=int(sqrt(a**2+b**2))
  for i in range(u-d,u+d):
    for j in range(v-d,v+d):
      if (((i-u)*cos(theta)+(j-v)*sin(theta))**2)/a**2+(((i-u)*sin(theta)-(j-v)*cos(theta))**2)/b**2<1:
        set_pixel(i,j,color)

def boucles():
  ellipse(100,100,20,5,6,green)
  ellipse(100,99,10,2,6,grey)
  ellipse(70,87,20,5,90,green)
  ellipse(72,85,10,2,90,grey)
  
def boite():
  fill_rect(85,105,40,40,red)
  fill_rect(35,105,40,40,red)
  fill_rect(85,150,40,40,red)
  fill_rect(35,150,40,40,red)
  fill_rect(35,145,90,5,green)
  fill_rect(75,105,10,85,green)
  
def cadeau():
  background()
  boucles()
  boite()
  
def tout():
  background()
  neige=[[randint(0,320),randint(0,200)] for i in range(50)]
  t=monotonic()
  while True:
   if monotonic()-t>.15:
    t=monotonic()
    for i,n in enumerate(neige):
      fill_rect(n[0],n[1],2,3,grey)
      n[1]+=randint(1,10)
      if n[1]>220: 
        [n[0],n[1]]=[randint(0,320),0]
      if n[0]>35 and n[0]<150 and n[1]>105: 
        n[1]+=100
      fill_rect(n[0],n[1],2,3,white)
    boucles()
    boite()
    ecriture()