circles.py

Created by schraf

Created on April 27, 2023

696 Bytes

“pion” dessine un pion de couleur “coul” aux coordonnées (c, l). Possibilité d’ajouter une ombre en utilisant le décalage “d” et une autre couleur, par exemple noire.

La boucle “for i in range(3): pion()” permet d’avoir un tracé plus net, essayez avec 2 ou sans la boucle pour voir la différence.


from kandinsky import *
from turtle import *
from random import *
from time import sleep

fond = (180,) * 3

def rect(c, l):
 fill_rect(160 + 30 * c, 111 - 30 * l, 25 , 25, fond)

def plateau():
 for c in range(-3,4):
  for l in range(-2,4): rect(c, l)

def pion(c, l, coul, d = 0):
  penup()
  goto(c + d, l - d)
  pendown()
  pensize(15)
  color(coul)
  goto(c + d, l - d)
  penup()

def cercle(c, l):
  u, v = 30 * c + 12, 30 * l - 12
  pion(u, v, (0, 0, 0), 2)
  for i in range(3): pion(u, v, (255, 0, 0)) 

plateau()
hideturtle()
c, l = 0, 0
while True:
  c = max(-3, min(3, c + randint(-1,1)))
  l = max(-2, min(3, l + randint(-1,1)))
  cercle(c, l)
  sleep(.8)
  rect(c, l)

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