réalise une mire dégradée de rectangles colorés dont la taille double à chaque itération en partant des extrêmités avec une taille choisie par rapport à la définition disponible de l’espace de dessin : 320 -> (2x5) x2x2x2x2x2 x 224 -> 7 x 2x2x2x2x2
La fonction degrade(nb) retourne une liste de taille nb generant un dégradé de couleurs ayant à peu près la même (intensité ?) en approximant une fonction sinus par un polynôme (pourquoi faire simple quand on peut faire compliqué, hein)
from kandinsky import * def degrade(nb): def valeur(x): x = x%150 if 0<x<100: return int(0.1*x*(100-x)) else : return 0 return [(valeur(x),valeur(x+50),valeur(x+100)) for x in range(0,150,150//nb)] w,h=10,7 fw,fh=320-2*w,224-2*h off_x,off_y=w,h couleurs=degrade(35) z=0 for k in range(4): for i in range(fw//w): for j in range(fh//h): if j==0 or i==0 or j==(fh//h)-1 or i==(fw//w)-1: fill_rect(w*i+1+off_x,h*j+1+off_y,w-2,h-2,couleurs[z%35]) z+=1 fw,fh=fw-2*w,fh-2*h off_x+=w off_y +=h w*=2 h*=2