嘿伙计们,我正在为 uni 做一个评估,我必须制作一本着色书,使用户能够使用空格键在两种模式之间切换。在第一种模式下,用户必须能够在不绘制任何线条的情况下移动海龟,而第二种模式必须启动用户可以绘制的画笔模式。我希望能够在 penup() 和 pendown() 之间切换按下空格键时海龟功能。有任何想法吗?
这是我到目前为止所拥有的:
from turtle import *
bgpic("Colour_A_Turkey.gif") # change this to change the picture
# PUT YOUR CODE HERE
setup(800,600)
home()
pen_size = 2
color("red")
title("Colouring Book")
speed("fastest") # Doesn't make any difference to accuracy, just makes turtle turn animation faster.
drawdist=10 # Distance in pixels pen travels when arrow key is pressed
penup()
###################BUTTON INSTRUCTIONS########################
def move_up():
seth(90)
forward(drawdist)
def move_down():
seth(270)
forward(drawdist)
def move_left():
seth(180)
forward(drawdist)
def move_right():
seth(0)
forward(drawdist)
def space_bar():
if isdown()==True:
penup()
if isdown()==False:
pendown()
####Change pen color####
def red():
color("red")
def green():
color("green")
def blue():
color("blue")
################BUTTON TRIGGERS##################
s= getscreen()
s.onkey(move_up,"Up")
s.onkey(move_down,"Down")
s.onkey(move_left,"Left")
s.onkey(move_right,"Right")
s.onkey(space_bar,"space")
s.onkey(red,"r")
s.onkey(green,"g")
s.onkey(blue,"b")
listen()
done()