140 lines
2.6 KiB
Python
140 lines
2.6 KiB
Python
|
#!/usr/bin/env python
|
||
|
from turtle import *
|
||
|
import math
|
||
|
import time
|
||
|
def pause():
|
||
|
input("pause>")
|
||
|
reset()
|
||
|
|
||
|
def exercice1(l): #J'ai mis un chiffre dans le nom de la variable pour me repérer
|
||
|
#Fonction carré
|
||
|
forward(l)
|
||
|
left(90)
|
||
|
forward(l)
|
||
|
left(90)
|
||
|
forward(l)
|
||
|
left(90)
|
||
|
forward(l)
|
||
|
left(90)
|
||
|
|
||
|
def exercice2():
|
||
|
exercice1(20)
|
||
|
left(90)
|
||
|
exercice1(40)
|
||
|
left(90)
|
||
|
exercice1(60)
|
||
|
left(90)
|
||
|
exercice1(70)
|
||
|
|
||
|
def exercice3():
|
||
|
speed('fastest')
|
||
|
for length in range(20, 200 ,20):
|
||
|
exercice1(length)
|
||
|
|
||
|
def exercice4():
|
||
|
speed('fastest')
|
||
|
for i in range(1,501):
|
||
|
forward(i)
|
||
|
left(91)
|
||
|
def exercice5():
|
||
|
def polygone(n, l):
|
||
|
for i in range(1,n+1):
|
||
|
forward(l)
|
||
|
left(360/n)
|
||
|
for i in range(3,7+1):
|
||
|
polygone(i,30)
|
||
|
def exercice6():
|
||
|
circle(70)
|
||
|
circle(70,360*2, 5)
|
||
|
|
||
|
def exercice7():
|
||
|
speed('fastest')
|
||
|
for i in range(72):
|
||
|
circle(70,180)
|
||
|
setpos(0,0)
|
||
|
left(5)
|
||
|
|
||
|
#FRACTALES
|
||
|
|
||
|
def exercice9():
|
||
|
left(180)
|
||
|
speed('fastest')
|
||
|
def sierpinski(n, l):
|
||
|
if n==1:
|
||
|
begin_fill()
|
||
|
for _ in range(3):
|
||
|
left(60)
|
||
|
forward(l)
|
||
|
left(60)
|
||
|
#circle(math.sqrt(((l)**2)/(2-2*math.cos(math.pi*30/180))),360,3)
|
||
|
end_fill()
|
||
|
else:
|
||
|
sierpinski(n-1, l/2)
|
||
|
left(60)
|
||
|
forward(l)
|
||
|
left(60)
|
||
|
sierpinski(n-1, l/2)
|
||
|
left(60)
|
||
|
forward(l)
|
||
|
left(60)
|
||
|
sierpinski(n-1, l/2)
|
||
|
left(60)
|
||
|
forward(l)
|
||
|
left(60)
|
||
|
sierpinski(5,300)
|
||
|
|
||
|
def exercice10():
|
||
|
left(90)
|
||
|
speed('fastest')
|
||
|
def bin_tree(n, h):
|
||
|
pensize(n)
|
||
|
forward(h/3)
|
||
|
if n!=1 :
|
||
|
left(30)
|
||
|
bin_tree(n-1, 2*h/3)
|
||
|
right(60)
|
||
|
bin_tree(n-1, 2*h/3)
|
||
|
left(30)
|
||
|
left(180)
|
||
|
forward(h/3)
|
||
|
left(180)
|
||
|
bin_tree(4,300)
|
||
|
def exercice11():
|
||
|
Alice = Turtle()
|
||
|
Bob = Turtle()
|
||
|
Alice.penup()
|
||
|
Bob.penup()
|
||
|
Bob.setpos(-60,-10)
|
||
|
Alice.setpos(0,40)
|
||
|
Alice.pendown()
|
||
|
Bob.pendown()
|
||
|
def tick():
|
||
|
Bob.forward(1.0)
|
||
|
Alice.setheading(Alice.towards(*Bob.position()))
|
||
|
Alice.forward(1.2)
|
||
|
while Alice.distance(*Bob.position()) > 2:
|
||
|
tick()
|
||
|
time.sleep(0.001)
|
||
|
|
||
|
|
||
|
"""exercice1(40)
|
||
|
pause()
|
||
|
exercice2()
|
||
|
pause()
|
||
|
exercice3()
|
||
|
pause()
|
||
|
exercice4()
|
||
|
pause()
|
||
|
exercice5()
|
||
|
pause()
|
||
|
exercice6()
|
||
|
pause()
|
||
|
exercice7()
|
||
|
pause()
|
||
|
exercice9()
|
||
|
pause()
|
||
|
exercice10()
|
||
|
pause()
|
||
|
exercice11()
|
||
|
pause()"""
|