# chocolate.py

Created by schraf

Created on December 21, 2022

6.35 KB

```from kandinsky import fill_rect, get_pixel
from random import randint, random, choice
from time import sleep
def draw_image(rle, x0, y0, w, pal, zoomx=1, zoomy=1, itransp=-1):
i, x = 0, 0
x0, y0 = int(x0), int(y0)
nvals = len(pal)
nbits = 0
nvals -= 1
while(nvals):
nvals >>= 1
nbits += 1
maskval = (1 << nbits) - 1
maskcnt = (0xFF >> nbits >> 1) << nbits
while i<len(rle):
v = rle[i]
c = (v & maskcnt) >> nbits
if (v & 0b10000000 or nbits == 8):
i += 1
c |= rle[i] << (7 - nbits + (nbits == 8))
c = c + 1
while c:
cw = min(c, w - x)
if mv != itransp:
fill_rect(x0 + x*zoomx, y0, cw*zoomx, zoomy, pal[mv])
c -= cw
x = (x + cw) % w
y0 += x == 0 and zoomy
i += 1

class particule():
def __init__(self):
self.x = randint(0,70)
self.y = randint(1,60)
self.v = 1
def tombe(self):
if self.y < 49 or self.y > 65: fill_rect(int(self.x), int(self.y), 1, 1, (0,0,0))
self.y += self.v
self.v += random()/3
self.x += randint(-1,1)
if self.y < 49 or self.y > 65: fill_rect(int(self.x), int(self.y), 1, 1, (216,200,216))

palette = (
"#081448","#000020","#606c98","#482c40","#281410","#482428","#604c58","#986450","k","#983c20","#582018","#d0c0c0","#504828","#b89468","#a098a8","#788080",
)
image = (
)
draw_image(image, 0, 1, 80, palette, zoomx=4, zoomy=4, itransp=-1)

neige = [particule() for _ in range(50)]
boules = (240,41),(248,73),(264,17),(272,17),(302,27),(216,93)
freq = (7,2,0),(7,2,0),(5,2,0),(5,2,1),(5,2,1),(1,2,2),(1,2,2),(0,3,2),(0,1,3)
coul = (213,213,160),(156,60,32),(74,44,65)

def alea(f):
t = sum(f)
s = f[0]
i = 0
r = random()
while r > s / t:
i += 1
s += f[i]
return i

def flamme():
for f in range(9):
y = 66 - 3 * f
for u in range(3):
x = 139 + 3 * u
c = coul[alea(freq[f])]
fill_rect(x,y,3,3,c)

def sapin():
(x,y) = choice(boules)
c = choice([(255,255,0),(0,255,0),(255,0,0),(0,0,255)])
fill_rect(x,y,3,3,c)

while True:
for p in neige:
p.tombe()
if get_pixel(int(p.x)+randint(-1,1),int(p.y)+1) == (216,200,216) or p.y > 160:
neige.remove(p)
neige.append(particule())
flamme()
sapin()
sleep(.1)```