franc_carreau.py

Created by elodie-gamot

Created on April 25, 2022

692 Bytes


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

def ligne(l):
  pendown()
  forward(l)
  penup()
  
def grille(l):
  #carreaux de côté l
  color('black')
  penup()
  speed(10)
  for i in range(-150,160,l):
    setheading(-90)
    goto(i,111)
    ligne(220)
  for j in range(-100,110,l):
    setheading(0)
    goto(-160,j)
    ligne(320)
    
def piece(r):
  #pièce de rayon r
  color('blue')
  speed(5)
  x=randint(-130,130)
  y=randint(-110,90)
  penup()
  goto(x,y)
  pendown()
  circle(r)

def jeu(n,l,r):
  #lancer n pièces de rayon r sur un damier dont les carreaux sont de côté l
  grille(l)
  for i in range(n):
    piece(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.