aiguilles_buffon.py

Created by elodie-gamot

Created on April 19, 2022

558 Bytes


from math import *
from turtle import *
from random import *

def ligne():
  pendown()
  setheading(-90)
  forward(220)
  penup()
  
def parquet():
  penup()
  speed(10)
  for i in range(-150,160,50):
    goto(i,111)
    ligne()
    
def aiguille():
  color(randint(0,255),randint(0,255),randint(0,255))
  speed(5)
  x=randint(-110,110)
  y=randint(-70,70)
  angle=randint(-180,180)
  penup()
  goto(x,y)
  setheading(angle)
  pendown()
  forward(50)

def buffon(n):
  parquet()
  for i in range(n):
    aiguille()
  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.