Desenhando com Python

$ python -V

Criando a sua “caneta” para desenhar

from turtle import Turtle, Screen, onkey, listen
window = Screen()
pen = Turtle()
def draw_pen():
window.exitonclick()
draw_pen()
python3 turtleDraw.py

Agora vamos fazer isso se mover

def draw_pen():
listen()
onkey(goFoward, "Up")
window.exitonclick()
def goFoward():
pen.foward(30)
draw_pen()
from turtle import Turtle, Screen, onkey, listen

window = Screen()
pen = Turtle()
def draw_pen():
listen()
onkey(goFoward, "Up")
onkey(turnLeft, "Left")
onkey(turnRight, "Right")
onkey(goBack, "Down")

window.exitonclick()
def goFoward():
pen.forward(30)
def turnLeft():
pen.left(30)
def turnRight():
pen.right(30)
def goBack():
pen.back(30)
draw_pen()

--

--

Interested in everything, writing about tech

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store