square.py

Created by schraf

Created on September 16, 2024

700 Bytes


from kandinsky import fill_rect

# Types de couleurs : bleu-rouge ou jaune-vert
coul = ((240,200,20), (90,150,80)), ((55,60,200), (220,25,35))

def tour(k):
    c = coul[k % 2] # choix couleur
    # Directions pour faire tour du carré
    dxy = (0, -1), (-1, 0), (0, 1), (1, 0)
    r = 0
    # Position (x,y) d'un tour
    x = k * (k - 1) / 2
    y = x
    for i in range(4 * k):
      # On dessine un carré de couleur
      fill_rect(160 + int(x), 111 + int(y), k, k, c[i % 2])  
      # si c'est un coin on change de direction
      if i > 0 and i % k == 0: r = (r + 1) % 4
      # Nouvelle position
      x += k * dxy[r][0]
      y += k * dxy[r][1]

for v in range(1, 19): tour(v)

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.