# -*- coding: utf-8 -*- import random as rd import turtle win = turtle.Screen() tt = turtle.Turtle() win.bgcolor('lightgreen') ###### def up(): tt.setheading(90) tt.forward(100) def down(): tt.setheading(270) tt.forward(100) def left(): tt.setheading(180) tt.forward(100) def right(): tt.setheading(0) tt.forward(100) def nw(): tt.setheading(135) tt.fd(50*(2**0.5)) def ne(): tt.seth(45) tt.fd(50*(2**0.5)) def sw(): tt.seth(225) tt.fd(50*(2**0.5)) def se(): tt.seth(315) tt.fd(50*(2**0.5)) def stamp(): tt.stamp() def chShape(): tt.shape(shapes[rd.randrange(len(shapes))]) def chColor(): tt.pencolor(rd.random(), rd.random(), rd.random()) win.listen() shapes = ['classic', 'arrow', 'turtle','circle','square','triangle'] win.onkey(up, '8') win.onkey(down, '2') win.onkey(left, '4') win.onkey(right, '6') win.onkey(nw, '7') win.onkey(ne, '9') win.onkey(sw, '1') win.onkey(se, '3') win.onkey(stamp, '5') win.onkey(chShape, '0') win.onkey(chColor, 'space') ###### win.exitonclick()