moteur_graphique.py

Created by alexandre-merle

Created on November 10, 2025

9.1 KB


from kandinsky import fill_rect
from random import randint
def Grey(c):return ((c[0]+c[1]+c[2])//3,)*3
def Blocks(t,x,y,l=0):
  if t=="0":
    fill_rect(x,y,24,24,(50,200,255))
  if t=="1":
    fill_rect(x,y,24,4,(20,180,20))
    fill_rect(x,y+4,24,20,(180,80,8))
    fill_rect(x,y+4,8,2,(20,180,20))
    fill_rect(x+2,y+6,4,2,(20,180,20))
    fill_rect(x+10,y+4,8,2,(20,180,20))
    fill_rect(x+10,y+6,6,2,(20,180,20))
    fill_rect(x+12,y+8,4,2,(20,180,20))
    fill_rect(x+12,y+10,2,2,(20,180,20))
    fill_rect(x+22,y+4,2,2,(20,180,20))
  if t=="2":
    fill_rect(x,y,24,24,(180,80,8))
  if t=="3":
    fill_rect(x,y,24,24,(70,)*3)
  if t in"45":
    fill_rect(x,y,24,12,(50,200,255))
    fill_rect(x,y+12,24,12,(50,160,50))
    fill_rect(x,y+10,6,2,(50,160,50))
    fill_rect(x+6,y+4,12,8,(50,160,50))
  if t in"5[":
    fill_rect(x+4,y+14,4,4,(245,50,50))
    fill_rect(x+10,y+6,4,4,(245,50,50))
    fill_rect(x+16,y+16,4,4,(245,50,50))
  if t in"6*":
    fill_rect(x,y,24,24,(70,)*3)
    fill_rect(x+6,y-22,12,2,(0,)*3)
    fill_rect(x+2,y-20,20,44,(0,)*3)
  if t in"7BPh":
    fill_rect(x,y,24,24,(20,)*3)
  if t=="8":
    fill_rect(x,y,24,24,(180,80,8))
    fill_rect(x+6,y-22,12,2,(100,50,5))
    fill_rect(x+2,y-20,20,44,(100,50,5))
  if t in"9HVvbp!":
    fill_rect(x,y,24,24,(125,65,5))
  if t in"Hh":
    fill_rect(x+2,y,4,24,(170,70,7))
    fill_rect(x+18,y,4,24,(170,70,7))
    fill_rect(x+6,y+2,12,4,(170,70,7))
    fill_rect(x+6,y+10,12,4,(170,70,7))
    fill_rect(x+6,y+18,12,4,(170,70,7))
  if t=="P":
    Player(ListPlr[0],x,y,2,0,Colors)
  if t=="p":
    Player(ListPlr[0],x,y,2,-1,{"1":(90,)*3,"2":(255,165,75),"3":(0,)*3,"4":(0,0,200),"5":(215,125,45),"6":(0,0,130),"7":(210,110,15),"8":(100,50,5),"9":(185,85,8),})
  if t=="!":
    Player(ListPlr[0],x,y,2,1,{"1":(90,)*3,"2":(255,165,75),"3":(0,)*3,"4":(0,0,200),"5":(215,125,45),"6":(0,0,130),"7":(210,110,15),"8":(100,50,5),"9":(185,85,8),})
  if t in"Vb}":
    fill_rect(x+10,y,4,24,(70,170,70))
    fill_rect(x+6,y+4,6,6,(100,210,100))
    fill_rect(x+12,y+16,6,6,(100,210,100))
  if t=="v":
    fill_rect(x+10,y+14,4,10,(70,170,70))
    fill_rect(x+8,y+14,4,4,(100,210,100))
    fill_rect(x+14,y+18,6,6,(100,210,100))
  if t=="b":
    fill_rect(x+14,y+4,4,4,(245,50,50))
    fill_rect(x+6,y+14,4,4,(245,50,50))
  if t in"Cc":
    if t=="C":fill_rect(x,y,24,2,(125,65,5))
    else:fill_rect(x,y,24,2,(20,)*3)
    fill_rect(x+2,y,20,2,(150,70,5))
    fill_rect(x,y+2,24,22,(150,70,5))
    fill_rect(x+2,y+2,20,6,(200,100,10))
    fill_rect(x+2,y+10,20,12,(200,100,10))
  if t=="T":
    fill_rect(x,y,24,24,(50,200,255))
    fill_rect(x+8,y-24,10,2,(20,150,20))
    fill_rect(x+4,y-22,16,4,(20,150,20))
    fill_rect(x+2,y-18,20,4,(20,150,20))
    fill_rect(x,y-14,22,2,(20,150,20))
    fill_rect(x,y-12,24,10,(20,150,20))
    fill_rect(x+2,y-2,22,2,(20,150,20))
    fill_rect(x+2,y,20,4,(20,150,20))
    fill_rect(x+4,y+4,16,2,(20,150,20))
    fill_rect(x+8,y,8,20,(135,35,4))
    fill_rect(x+6,y+20,12,4,(135,35,4))
    fill_rect(x+6,y-4,4,6,(135,35,4))
    fill_rect(x+12,y-2,6,4,(135,35,4))
    fill_rect(x+4,y-6,4,4,(135,35,4))
    fill_rect(x+16,y-4,4,4,(135,35,4))
  if t=="o":
    fill_rect(x,y,24,2,(50,200,255))
    fill_rect(x,y+2,24,2,(245,245,255))
    fill_rect(x,y+4,24,20,(80,180,225))
  if t=="a":
    fill_rect(x,y,24,2,(20,)*3)
    fill_rect(x,y+2,24,2,(245,255,245))
    fill_rect(x,y+4,24,20,(100,225,100))
  if t=="A":
    fill_rect(x,y,24,24,(100,225,100))
  if t=="B":
    fill_rect(x,y+22,24,2,(140,40,4))
  if t=="O":
    fill_rect(x,y,24,24,(0,140,190))
  if t=="]":
    fill_rect(x,y+10,24,4,(140,40,4))
  if t=="=":
    fill_rect(x+10,y+6,2,2,(185,185,205))
    fill_rect(x+6,y+8,10,14,(185,185,205))
  if t==">":
    fill_rect(x+10,y+6,2,2,(100,225,100))
    fill_rect(x+6,y+8,10,14,(100,225,100))
  if t=="<":
    fill_rect(x+10,y+6,2,2,(40,180,230))
    fill_rect(x+6,y+8,10,14,(40,180,230))
  if t in"=<>":
    fill_rect(x+10,y+4,2,2,(235,235,255))
    fill_rect(x+8,y+4,2,4,(235,235,255))
    fill_rect(x+12,y+4,2,4,(235,235,255))
    fill_rect(x+6,y+8,2,2,(235,235,255))
    fill_rect(x+14,y+8,2,2,(235,235,255))
    fill_rect(x+4,y+10,2,12,(235,235,255))
    fill_rect(x+16,y+10,2,12,(235,235,255))
    fill_rect(x+6,y+22,10,2,(235,235,255))
  if t=="{":
    fill_rect(x+10,y+2,2,2,(180,180,180))
    fill_rect(x+10,y+4,4,8,(180,180,180))
    fill_rect(x+10,y+12,4,8,(140,40,4))
ListPlr=[
"000111111110001111111110001221223200001221222200001122222200007664444550077666224450077766224400077444444300008888888300000099900000000099990000",
"000111111110001111111110001221223200001221222200001122222200007664444500077666622400077766622400977444444300998888888399099900009990000000000000",
"000111111110000111111111000023221221000022221221000022222211000054446660000022666664000082666644777778377777077773877777077777887777007777888770",
"000111111110000111111111000023221221000022221221000022222211000004444660000044422664000044482644777773877777077778377777077788777777007888777770",
"001111111100011111111110011111111110011111111110011177771110004777777450057777777750057777777700004777777400008888888800009990099900000000099900"]
Colors={"1":(90,)*3,"2":(255,165,75),"3":(0,)*3,"4":(200,0,0),"5":(215,125,45),"6":(130,0,0),"7":(210,110,15),"8":(100,50,5),"9":(185,85,8),}

def _Player(l, x, y, s, p, c):
  # p : -1 = gauche, 0 = gris (statue), 1 = droite
  for Y in range(12):
    X = 0
    while X < 12:
      # Sélection du pixel en fonction du sens
      idx = Y * 12 + (11 - X if p != 1 else X)
      px = l[idx]
      if px != "0":
        X2 = X
        # Regrouper les pixels contigus de la même couleur
        while X2 < 12 and l[Y * 12 + (11 - X2 if p != 1 else X2)] == px:
          X2 += 1
        # Choisir la couleur selon le mode
        col = c[px]
        if p == 0:  # gris / statue
          g = (col[0] + col[1] + col[2]) // 3
          col = (g, g, g)
        # Dessiner le rectangle regroupé
        fill_rect(
          x + ((12 - X2 if p == -1 else X) * s),
          y + Y * s,
          (X2 - X) * s,
          s,
          col
        )
        X = X2
      else:
        X += 1


def Player(l,x,y,s,p,c):
  for i in range(144):
    if l[(i//12*12)+(11-i%12)]!="0"and p==0:fill_rect(x+((i%12)*s),y+((i//12)*s),s,s,Grey(c[l[(i//12*12)+(11-i%12)]]))
    elif l[i]!="0"and p==1:fill_rect(x+((i%12)*s),y+((i//12)*s),s,s,c[l[i]])
    elif l[(i//12*12)+(11-i%12)]!="0"and p==-1:fill_rect(x+((i%12)*s),y+((i//12)*s),s,s,c[l[(i//12*12)+(11-i%12)]])

def set_block(m,x,y,nb):
  m[y]=m[y][:x]+nb+m[y][x+1:]

def MAP(m,x,y,l=0):
  for Y in range(-1,10):
    for X in range(-1,14):
      Blocks(m[Y-(y//24)][X-(x//24)],(X*24)+(x%24),(Y*24)+(y%24),l)
      if m[Y-(y//24)][X-(x//24)]=="4"and randint(1,200)==1:
        set_block(m,X-(x//24),Y-(y//24),"5")
Grid=[
"22221000000000000000000000000000000000000000000003333",
"22222000000000000000000000000000000000000000000033333",
"22222100000000000000000000000000000000000000000033333",
"22222240000000000000000000000000000000000000000033333",
"22222210000000000000000000000000000000000000000333333",
"22222220000000000000000000000000000000000000000333333",
"22222220000000000000000000000000000000000000003333333",
"222222805T000504T000000000000000000000000000003333333",
"22222221111111111500000000000000000000000000033333333",
"2222222222222222211104050000000000000000000T063333333",
"222222222222222222221111oooooooooooooooooo33333333333",
"222222222222222222222222OOOOOOOOOOOOOOOOOO33333333333",
"22222222222222222222222222OOOOOOOOOOOOOOO333333333333",
"222222222222222222222222222OOOOOOOOOOOOOO333333333333",
"222222222222222222222222222OOOOOOOOOOOOOO333333333333"]
Cave=[
"3333333333333333333333333333333333333",
"3333333333333333333333333333333333333",
"3333333333777777733333377733333333333",
"333333337777777777777hP7777c333333333",
"333333377h77733333333h333333333333333",
"333333333h33333377333h777773333333333",
"333333333h33337777733h777777h33333333",
"333333333h337777777733333333h33333333",
"333333377h367777777777777773h33333333",
"333333*77h33377777777777777Ph33333333",
"333333333333333aaa333a33aa33333333333",
"333333333333333AAA333A33AA33333333333",
"333333333333333AAA333333AA33333333333",
"3333333333333333333333333333333333333",
"3333333333333333333333333333333333333"]
Dirt=[
"22222222222222222222222222222222",
"2222222222299V992222222222222222",
"22222222999v9b999H22222222222222",
"22222222vC9b22222H22222222222222",
"22222222122229999HV9999222222222",
"22222222999999999Hb99vp222222222",
"22222222H99v99992222221222222222",
"22222222H22222222V9999V222222222",
"22222222H99v99V99V9999b822222222",
"22222222229b99V9vb99v22222222222",
"22222222222221221222222222222222",
"22222222222222222222222222222222",
"22222222222222222222222222222222",
"22222222222222222222222222222222",
"22222222222222222222222222222222"]
Cave2=[
"22222222222222222223333333333333",
"222222222b9999222333333333333333",
"2222222b9999v9923333333333333333",
"22222299v999V99V7777733333333333",
"22222299V999V9977777777733333333",
"222222!9VCv9b77777777777*3333333",
"2222222222222aaaaaa3333333333333",
"2222222222222AAAAAA3333333333333",
"22222222222222AAAA33333333333333",
"22222222222222333333333333333333",
"22222222222223333333333333333333",
"22222222223333333333333333333333",
"22222223333333333333333333333333"]

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