2022-10-06 16:13:06 +02:00
|
|
|
from uturtle import (
|
|
|
|
umonsTurtle, wait,
|
|
|
|
moveForward, moveBackward,
|
|
|
|
turnLeft, turnRight,
|
|
|
|
dropPen, usePen)
|
|
|
|
|
|
|
|
|
|
|
|
def koch(t: umonsTurtle, x: int, seuil: int):
|
|
|
|
"""Dessine une courbe de koch
|
|
|
|
|
|
|
|
:t: the turtle used
|
|
|
|
:x: the length
|
|
|
|
:seuil: seuil of smallest step
|
|
|
|
:returns: None
|
|
|
|
|
|
|
|
"""
|
|
|
|
if x < seuil:
|
|
|
|
moveForward(t, x)
|
2022-11-24 09:49:57 +01:00
|
|
|
else:
|
|
|
|
koch(t, x/3, seuil)
|
|
|
|
turnLeft(t, 60)
|
|
|
|
koch(t, x/3, seuil)
|
|
|
|
turnRight(t, 120)
|
|
|
|
koch(t, x/3, seuil)
|
|
|
|
turnLeft(t, 60)
|
|
|
|
koch(t, x/3, seuil)
|
2022-10-06 16:13:06 +02:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
turtle = umonsTurtle()
|
|
|
|
turtle.speed(0)
|
|
|
|
dropPen(turtle)
|
|
|
|
moveBackward(turtle, 250)
|
|
|
|
usePen(turtle)
|
2022-11-24 09:49:57 +01:00
|
|
|
koch(turtle, 500, 20)
|
2022-10-06 16:13:06 +02:00
|
|
|
wait()
|