wallpaper3.py

Created by schraf

Created on October 19, 2022

760 Bytes

Enchevêtrements

Actualisez la page pour obtenir un autre motif !

Explications du code

from kandinsky import *
from math import sqrt
from random import randint

# nb d'anneaux (couleurs alternées) et largeur anneau
(nb, r) = (randint(3,40), randint(2,10)) 
p = nb * r
COUL = (70, 75, 75)
fill_rect(0, 0, 320, 222, (255, 210, 0))

def cercles(u,v,du,dv):
 # Bord opposé (en diagonale) au point de départ (u,v)
 (u2, v2) = (u + du * nb * r, v + dv * nb * r)
 # Pour chaque pixel du carré p * p
 for x in range(p):
    for y in range(p):
     # Recherche du n° de l'anneau
     d = int(sqrt(x ** 2 + y ** 2) / r)
     # Si c'est un nb impair et qu'il est inférieur au nb d'anneaux total
     if d & 1 and d < nb:
        # On le dessine (gris foncé)
        set_pixel(u + du * x, v + dv * y, COUL)
        # Distance point par rapport à l'autre extrémité
        # et calcul du n° de l'anneau
        d2 = int(sqrt((x - p) ** 2 + (y - p) ** 2) / r)
       # On dessine pixel si en dehors des anneaux précédents
        if d2 > nb - 2:
         set_pixel(u2 - du * x, v2 - dv * y, COUL)

def motif(x,y):
 # (a,b) = position départ du motif et (c,d) = directions du remplissage en x et y
 # Faire varier (c,d) avec d'autres combinaisons de 1 et -1
 for (a,b,c,d) in ((1,1,-1,-1),(2,0,-1,1),(0,2,1,-1),(1,1,1,1)):
    cercles(x + a * p, y + b * p, c, d)

for c in range(1+ 160 // p):
 for l in range(1 + 110 // p):  motif(2 * c * p,2 * l * p)


from kandinsky import *
from math import sqrt
from random import randint

nb, r = randint(3,40), randint(2,10)
p = nb * r
COUL = (70, 75, 75)
fill_rect(0, 0, 320, 222, (255, 210, 0))

def cercles(u,v,du,dv):
 (u2, v2) = (u + du * nb * r, v + dv * nb * r)
 for x in range(p):
  for y in range(p):
    d = int(sqrt(x ** 2 + y ** 2) / r)
    if d & 1 and d < nb:
      set_pixel(u + du * x, v + dv * y, COUL)
      d2 = int(sqrt((x - p) ** 2 + (y - p) ** 2) / r)
      if d2 > nb - 2:
        set_pixel(u2 - du * x, v2 - dv * y, COUL)

def motif(x,y):
 for (a,b,c,d) in ((1,1,-1,-1),(2,0,-1,1),(0,2,1,-1),(1,1,1,1)):
    cercles(x + a * p, y + b * p, c, d)

for c in range(1+ 160 // p):
 for l in range(1 + 110 // p):  motif(2 * c * p,2 * l * p)