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)

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