boulevirus.py

Created by schraf

Created on October 09, 2022

662 Bytes

Art génératif : Partie 2 - Le hasard

Art génératif : Partie 1 - Transformations affines


import turtle
from random import randint, random
from math import log
n, t = 0, turtle
t.speed(0)
# On part sur 100 000 segments
while n < 1e5:
 # Recup position tortue
 (x, y) = t.position()
 n += 1
 # Tortue sortie disque rayon 100 ?
 # Utilisation Th Pythagore
 if x*x + y*y > 1e4:
  # Si oui la tortue retourne au centre 
  t.penup()
  t.goto(0,0)
  t.pendown()
  # On change de couleur
  t.color((randint(0,250),) * 3)
 else:
  # Sinon elle choisit une direction au hasard 
  t.setheading(randint(0, 359))
  # et avance d'une longueur aleatoire
  # ici loi exponentielle
  # mais on peut mettre t.fd(4) ou autre
  t.fd(-log(random()) / .1)