Skip to content

Instantly share code, notes, and snippets.

@rochacbruno
Last active July 26, 2022 14:31
Show Gist options
  • Save rochacbruno/faec0cf1379ff3c25b48001b0e5872ec to your computer and use it in GitHub Desktop.
Save rochacbruno/faec0cf1379ff3c25b48001b0e5872ec to your computer and use it in GitHub Desktop.
Turtle e Pattern Match
"""Turtle module http://cursodepython.com.br"""
import turtle
turtle.bgcolor("black")
turtle = turtle.Turtle()
turtle.shape("turtle")
turtle.speed(3)
turtle.width(10)
turtle.color("blue", "yellow")
turtle.pencolor("red")
turtle.penup()
while True:
command: lis1t[str] = input("🐢>").strip().split()
match command:
case ["move", *points]:
match points:
case [x, y]:
turtle.goto(float(x), float(y))
case [steps]:
turtle.forward(float(steps))
case ["turn", *options]:
match options:
case [angle]:
turtle.right(float(angle))
case _:
turtle.right(90)
case ["draw", shape, size]:
turtle.pencolor("red")
turtle.pendown()
match shape:
case "circle":
turtle.circle(float(size))
case "line":
turtle.forward(float(size))
turtle.penup()
case ["write", *text]:
turtle.write(" ".join(text), None, "center", "16pt 20")
case ["exit" | "stop" | "quit"]:
break
case _:
print("Invalid command")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment