cours_progra/q1/04oct/ex3.py
2023-02-15 13:40:50 +01:00

37 lines
733 B
Python

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)
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)
if __name__ == "__main__":
turtle = umonsTurtle()
turtle.speed(0)
dropPen(turtle)
moveBackward(turtle, 250)
usePen(turtle)
koch(turtle, 500, 20)
wait()