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]
    mv = v & maskval
    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 = (
b"\xc0\1a\2\x93\1\4\1\4\25\3\5\24\3\6\5\6\a\6\24\b\xa4\19\b\24\b\24\x1848\xc0\1a\2\x93\1\4\1\4\25\23\24\23\5\6\a\6\x84\1\x054)\n4\b\4\b\4\5$8\xb0\1\xf1\0\2\3\6\xf3\x004%\24\25\4\6\27\24\b\4\5\xf4\0\5*\4\5*\4(\32$(\xb0\1\xf1\0\2\x83\1\x054%\1\24\5\4\6\27\5\4\b\xc4\1\25\24\n\t\nTH\xa0\1\x81\1\2\x83\1\x054\3\25\1$\5&\5\4\b\xa4\1\5\24\5\4\n\t\v\t\n\24\5\4X\x90\1\x91\1\2\x83\1\5$54\5\26\a\5\4\30%\4\5\4\aD\5\f\24\n\t*\4\6\n\48\4\x90\1\x91\1\2\x83\x014\25\3\x054\5\6\3\6\5$e\4\5\x1a4\5\24\n\t\v*\31(\4\x80\1\xa1\1\2\x83\x014\25\x034\5\3\34\3\5$E\n\5\4\n\v\t\n\4\3\f4\a\v\n\4\n\33\4\30\4\x80\1\xa1\1\2C\5\23\5\3$\25\x034\5\23\5\x034\5:\34\5*\25\4\5\34\4\b\4\n\4\b\4\32(\4\xf0\0\xb1\1\2C\5\3\25\3$\25\x034%\f\3\5\24\5\32\26\5\4\5$\5\24\b\4\f\24\30\24\5\n\5\6(\4\xf0\0\xb1\1\x023U$%4%\26\5\24\f\32\t\6\30\4\25\a\t\5\4\b\4\5\24(\4\25\6\3\30\24`\xc1\1\2\23\5\3e\24\5\3\x054\5\23\26\5\24\f\32\t\6\4\b$\v\r\f\4\b\4\5D\5\4\34(\4\f\xb2\2\6\23\5\3\xf5\0\4\5\3\v4\5\3\f\a\6\f\24\n\5\32\a\t\34\24\32\5\4\30\4\5\f$<\4\6\30\f\x83\x016W\6\23\5\3\x85\1\24\5\v$\25\3\n'Z\a\t\r\v\f\24\5\4(T\6,\30\4\b\4\xa3\1\6'-'\x065\4U\24\5\v4\5\3\n'Z\a\t\a\6\f\4\b$\30\24\5\f\24<(\24\x90\1#&\x176\3%\4%\4\25\4\5\a\v$\5\f\5\n\a\r\a\32\t:\f\6\5\30\24\30\4\30\24\fDX\xb1\2\6\a\6\25\24\25\24\25\4\5\33$\5\f\5\f\a\r\a\n'\f\n\5\4(T(\3D\fX\xb1\2\6\a\6\25\24\25\24\25\24\33$\5\3\n\6'\n7\32\5\4(d\b4\f\27$(\xb1\2\6\a\6\25\24\5\24%\4\5\33$\23\5\6'\n7\f\5$\30$\t\n\30\4\f%\n)\48\xb1\2\6\27\6\25\4\25\24\25\n\16\33\r\a\25\32\f\6\27\n7\x064\5$\5\v\r\b\4\f\25\f\v\27\31\32(\xa1\2\b\6'\6%\4\5\4\5\x8b\1\32\f\26\f\nG\5\n\f\4\5\f\4\30\32\34%\6\a\n\4\b\24\n\b\4\b\x91\2\30\x067\6\n%\4\xab\1&%\31'\f\a\f\25T\f\4\b\24;\a\f\32\24\b\x91\2\30\3G\6\t\6\5\4\xab\1\6\x035L\n\r\n\25\4\30\4\b\4\x054\a+\a\n\4\n\4\30\xf1\18\3\xf7\0\f\n\xab\1\n\5\32\f\5,\n\16\a\t\n\4<$\f\n\4\v\5\f\r\v'\32\t\b\4\xe1\1H\3W\35\a\5\xab\1\32\6\27\n\a\31\f\v\r\31\4\6,\5\4\5\n\f\b\v\16\f\5-\t\n$\v\xc1\1h\3\6W\r\t\6\xab\1\f\t-\t'\t\4\r\n\t\n,\4\f\t\r\33\4\v\b\33\r\a\31\n$\r\xa1\1\x88\1\3\f\tG\r\n\a\xab\1\27-\t\35\27\n\r\31\4,\4\n\33\4\v\b\3\v\6\33\b\v\30$\b\x91\1\x98\1\3\n\f\6\t'\r\t\a\x9b\1\r\a\35\v\r\n\35'\32\4\b\4\r\v\17\6\v\b\v\b\v\b\16\b\v\b\16\v\16\f\b$\x81\1\xa8\1\3\25<\27\t\a\x9b\1\r\a=\t\a\r\a\t\f\4\f\4\b\37\f\a\30\26\33\b\4\30\33\36\26(\xf1\0\xb8\1\3%\n\5\n\27\31\x9b\1\16\27-\t'\tD\6\34\17\v\16\b+\b\4\16\b\v\4\16\a\5\6\5\30Q\xd8\1\4U\f\t\f\n\x9b\1\16\27-\n'\f\24\b\4\f\6$K\16\a\6\36\v\17\6\a\5\b\5\6\bA\xe8\1\4%\24\25\f\32\x9b\1\a\f\a\35\a\n\t\a\f$\b\24\a\34\4K.\r\a\r'\4\b\5\a\b!\x88\2%\4%\f\n\f\5;.+\a\n\6'\f\t\f\n\4\x054\6\f\b\4]'\n\t*\4\v\a\v\b!\x88\2e,\n;.\33\16\6\32\t\27\f\32\f\n\25$\f$-\27\31j\5\4\f\v\4\1\xa8\2\3\x1c5\n\3\34+n\6\32\t\a\f\n\5\f\6\x1a4\f\4\2\4-\27\31j\4\f\v\34\xb8\2\3\a\t\f5\3\34+n\6\4\32\34\5\4,\n4\b\f\30-'\tj\4\f\17\a\n\xb8\2\6'\f\nE+n\6\24\5\f\n\25\f\4\32\24\n4\5-'\tj\f\a\b\4\f\xb8\2\6'\t\f\n\f\5\f\6+n\6\4%\32\34\4\n$\n\t\24\b\f=\27\tj\6(\4\xb8\2\6-\a\t\f\6\f\a\n\t\27n\a\24\25\n\4\5,\n\t\r\n\v\t\30\f\a\t\a\r\27\tj\v\f\4\b\4\xb8\2\6-\27\t\a\6\f\n\a\n\a\6^\a%\24\5$\34\t\v\t\n\v\4\a\r\f\r\f\r\27\tj\t\f\n\24\xb8\2\6=7\32\34\32\aN\6\f\n\5$\5$\26\n\t\6\4\v\r\t\f\t\f\a\r\a\tZ\t\n\4\f\4\fB\xee\1\6=7\f\t:\f\17.\17\a\6\x1a5\34\3F\16\35'\r\f\27\tJ\4\rFK\16\v\xee\1/\6\16\17\16\a\t\n\a\n\34>\17\a\n\4\x056\3E\n\5\27\r,\t\34\r:\24e^o\6\17\2V\3\6\3\f&\n\f\32\a\4\n\36\37\26\n\4\25\n\x86\1\r\t\27\rL\t\a\n\24\5\a6#\v\xfe\x012\16\22\6\a\r\f'\n\a\n\4\n\5\17\3&\5\26\n\5\n\xf7\0\v\r\32\a,\n\t\a\16\n\24\f\36V+n\x82\1\36?4\16\4\n\a*\4\t\26\f\27\5\n\t\6\25\6W+].\a\17\f\6\v\16\4\5\23\5\3\xce\2\2\6\24\f\b$\b\6\5\24\t\32\r'$\5\4\5\4f\a\v\r\33\16\a\v7.\26\4\x156B\16\"\16B\26\2\26\22\6\4\b\4\6\bD\b\4\n\5\f\4\f\4\25D\5\23\26\23\17\6\v-\27\r\t\n\6%DE\"\6\20\6\3\20\3 \3\0\x030\6\2\6\4\b\4H\4\30\4\b\4\6\b\f\b\24\f\4\b$\5\23\25\23\16-'\t\n\25\24%T\5\36\v>\2\xbe\1\2\16\22\3X\24\6\b4(\4\b\4\30\24\3\4\22\26\"\6\5&\5\4\xd5\1\3\xfe\1\x82\1\24\25\4\b\4(\4\3\4\5H\4\xf8\0\3\0\4@\4\1d\3\5\xf4\0\"\6\xa2\1\16\17.\17\16\17\16\2.\26\f\xb6\1\3%45\17\6\x036\17\2\x063\6\3\xf6\0\3\6\23\0\3\6\23\2\26\3\26#\26\23&B\16\17\23\6\5\f\6\f\5,f\f\25\xa6\1\3\26#\5\3\5\23%$\2\3\0\6\2\3\6\2#&\"\x062\17\16\2\17\36\17N\v.g\t\aY\f\n\f'\x0f6?\a\xf6\0\23\6\v\36\33\16\33\xbe\2+\16K\16\33\36G\xba\1\3\xf6\0\3\26S\5\24"
)
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)

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>.