cercles.py

Created by schraf

Created on August 28, 2025

598 Bytes


from random import *
from turtle import *

# coordonnees rectangle virtuel
xmin, xmax, ymin,ymax = -140, 140, -105, 105
speed(0)

def alea(mini, maxi): return mini + (maxi - mini) * random()

for i in range(500):
  # Centre du cercle
  x, y = alea(xmin, xmax), alea(ymin, ymax)
  # Calcul du rayon max
  r = int(min(xmax - x, x - xmin, ymax - y, y - ymin))
  # Couleur dependant du rayon ou rouge si multiple de 20
  coul = (2 * r,) * 3 if i % 20 else (255,0,0)
  # Tracage du cercle
  penup()
  goto(x + r, y)
  pencolor(coul)
  setheading(90)
  pendown()
  circle(r)
hideturtle()  

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.