# noelnw.py

Created by schraf

Created on December 16, 2019

1.27 KB

Apprendre Python sur une Numworks

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

def rec(x,y,c,t):
fill_rect(x,y,2*t,3*t,c)

def rd():
return randint(0,255)

def go():
# Initialisation
txt=["JOYEUX","NOEL","AVEC","NUMWORKS"]
neige=[[randint(0,320),randint(0,200)] for i in range(100)]
t=monotonic()
# Effacer ecran
fill_rect(0,0,320,240,(0,0,0))
while True:
# Toutes les 0.15 secondes
if monotonic()-t>.15:
t=monotonic()
# Le sapin avec boules lumineuses
for i in range(1,12):
for j in range(i):
c=(rd(),rd(),rd()) if random()>0.7 else (0,180,0)
rec(80-5*i+10*j,15+17*i,c,2)
# 50 flocons de neige
for i,v in enumerate(neige):
rec(v[0],v[1],(0,0,0),1)
v[1]+=randint(1,10)
if v[1]>240: [v[0],v[1]]=[randint(0,320),0]
c = (140,140,140)
rec(v[0],v[1],c,1)
# Le texte
for i,v in enumerate(txt):
[av,arr] = [(255,0,0),(255,255,255)]
for j,c in enumerate(v):
if random()<.1 : [av,arr] = [arr,av]
draw_string(c,160+18*j,70+35*i,av,arr)
# Les guirlandes
for i in range(40):
r=choice([(255,0,0),(255,255,255)])
fill_rect(8*i,int(15+8*sin(3.14*i/8)),4,4,r)
fill_rect(int(270-30*cos(6.28*i/40)),int(130-30*sin(6.28*i/40)),4,4,r)
go()```