0% found this document useful (0 votes)
20 views2 pages

From Turtle Import

The document contains Python code to generate a forest scene with randomly placed trees and stars. It defines functions to draw triangles for tree tops, rectangles for tree trunks, recursive functions to draw full trees, and stars. The main function calls the tree and star functions to generate a forest with 2 trees and 5 randomly placed stars.

Uploaded by

Milo CONSOLO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

From Turtle Import

The document contains Python code to generate a forest scene with randomly placed trees and stars. It defines functions to draw triangles for tree tops, rectangles for tree trunks, recursive functions to draw full trees, and stars. The main function calls the tree and star functions to generate a forest with 2 trees and 5 randomly placed stars.

Uploaded by

Milo CONSOLO
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

from turtle import*

from random import*


from math import*
speed(0)
hideturtle()
setup(640,480)
up()
goto(-700,700)
down()
color('black', 'mintcream')
begin_fill()
for i in range(4):
forward(1400)
right(90)
end_fill()

def triangle(x,y,cote):
color('black', 'darkgreen')
begin_fill()
up()
goto(x,y)
down()
for i in range(3):
forward(cote)
left(120)
end_fill()

def tronc(x,y,n):
up()
goto(x,y)
forward(n/3)
down()
color('black', 'sienna')
begin_fill()
for i in range(4):
forward(n/3)
right(90)
end_fill()
up()

def sapin(x,y,n):
tronc(x,y,n)
for s in range(floor(n/40)):
triangle(x+s*15,y+s*50,n-s*30)

def foret(nb_arbre):
for i in range(nb_arbre):
x=randint(-350,200)
y=randint(-200,200)
cote=randint(100,200)
sapin(x,y,cote)
for i in range(5):
etoile(1,randint(5,40))

def etoile(nb,taille):
setheading(96)
for i in range(nb):
up()
goto(randint(-350,200),randint(-200,200))
down()
color('gold','yellow')
begin_fill()
for h in range(4):
right(15)
forward(taille)
left(15)
forward(-taille)
right(90)
end_fill()

foret(2)
exitonclick()

You might also like