所以这个程序让我可以制作一个可定制的简笔画。我对 python 很陌生,这是我在学校计算机科学之外的第一个大项目。由于身体手臂的坐标在不同的地方结束,我需要来自 bodyfunc、short、medium 和 long 的坐标。该程序有效,但由于某种原因,它没有获取值并将其传递给我的尾部/附件函数。你能看看我的程序并帮助我!
import turtle
#Head
def headfunc(headtype, headcolor, headpensize):
head=turtle.Turtle()
head.color(headcolor)
head.pensize(headpensize)
if headtype=="square":
wn = turtle.Screen()
head.penup()
head.left(90)
head.forward(200)
head.pendown()
head.left(90)
head.forward(50)
head.right(90)
head.forward(100)
head.right(90)
head.forward(100)
head.right(90)
head.forward(100)
head.right(90)
head.forward(50)
elif headtype=="round":
wn = turtle.Screen()
head.penup()
head.left(90)
head.forward(200)
head.right(90)
head.pendown()
head.circle(50)
elif headtype=="diamond":
wn = turtle.Screen()
head.penup()
head.goto(0,200)
head.pendown()
head.goto(35,300)
head.goto(0,400)
head.goto(-35,300)
head.goto(0,200)
else:
print("Not valid")
# Body
def bodyfunc(bodytype,bodycolor, bodypensize, endbody, endarm_x, endarm_y):
body=turtle.Turtle()
body.color(bodycolor)
body.pensize(bodypensize)
if bodytype=="short":
bodylength = 200
wn = turtle.Screen()
body.penup()
body.goto(0,200)
body.pendown()
body.goto(0,200-bodylength) #Body Length
body.goto(0,200-3*bodylength/8) #Body(Reposition)
body.goto(bodylength/2,200-bodylength/4) #Arm Length (Right)
body.goto(0,200-3*bodylength/8) #Body (Reposition)
body.goto(-bodylength/2,200-bodylength/4) #Arm Length (Left)
body.goto(0,200-3*bodylength/8) #Body (Reposition)
body.goto(0,200-bodylength) #Body (Reposition)
body.goto(bodylength/4, 200-3*bodylength/2) #Leg Length (Right)
body.goto(0,200-bodylength) #Body (Reposition)
body.goto(-bodylength/4,200-3*bodylength/2)#Leg Length(Left)
endbody = 200-bodylength
endarm_x = bodylength/2
endarm_y = 200-bodylength/4
return endbody, endarm_x, endarm_y
elif bodytype=="medium":
bodylength = 300
wn = turtle.Screen()
body.penup()
body.goto(0,200)
body.pendown()
body.goto(0,200-bodylength) #Body Length
body.goto(0,200-3*bodylength/8) #Body(Reposition)
body.goto(bodylength/2,200-bodylength/4) #Arm Length (Right)
body.goto(0,200-3*bodylength/8) #Body (Reposition)
body.goto(-bodylength/2,200-bodylength/4) #Arm Length (Left)
body.goto(0,200-3*bodylength/8) #Body (Reposition)
body.goto(0,200-bodylength) #Body (Reposition)
body.goto(bodylength/4,200-3*bodylength/2) #Leg Length (Right)
body.goto(0,200-bodylength) #Body (Reposition)
body.goto(-bodylength/4,200-3*bodylength/2)#Leg Length(Left)
endbody = 200-bodylength
endarm_x = bodylength/2
endarm_y = 200-bodylength/4
return endbody, endarm_x, endarm_y
elif bodytype=="long":
bodylength = 400
wn = turtle.Screen()
body.penup()
body.goto(0,200)
body.pendown()
body.goto(0,200-bodylength) #Body Length
body.goto(0,200-3*bodylength/8) #Body(Reposition)
body.goto(bodylength/2,200-bodylength/4) #Arm Length (Right)
body.goto(0,200-3*bodylength/8) #Body (Reposition)
body.goto(-bodylength/2,200-bodylength/4) #Arm Length (Left)
body.goto(0,200-3*bodylength/8) #Body (Reposition)
body.goto(0,200-bodylength) #Body (Reposition)
body.goto(bodylength/4,200-3*bodylength/2) #Leg Length (Right)
body.goto(0,200-bodylength) #Body (Reposition)
body.goto(-bodylength/4,200-3*bodylength/2)#Leg Length(Left)
endbody = 200-bodylength
endarm_x = bodylength/2
endarm_y = 200-bodylength/4
return endbody
else:
print("Not valid")
# Tail
def tailfunc(tail, endbody):
if tail=="yes":
wn = turtle.Screen()
tail=turtle.Turtle()
tail.penup()
print(endbody)
tail.goto(0,endbody)
tail.pendown()
tail.color("brown")
tail.right(65)
tail.circle(60,200)
tail.shape("triangle")
elif tail=="no":
quiterty=1
else:
print("Not valid")
def accessories1func(accessories1, endarm_x, endarm_y):
a=turtle.Turtle()
if accessories1=="sword":
wn = turtle.Screen()
a.goto(endarm_x, endarm_y)
a.forward(100)
wn.mainloop()
def main():
headtype=input("Enter head(square,round,diamond)")
headcolor=input("Head Color?:Red,white,black,gray,brown,gold,purple,blue,cyan")
headpensize=input("Head pensize? 1-5")
bodytype=input("Enter body(short,medium,long")
bodycolor=input("Body Color?:Red,white,black,gray,brown,gold,purple,blue,cyan")
bodypensize=input("Head pensize? 1-5")
tail=input("Tail: Yes or no")
accessories1=input("sword,staff,gun,bow")
endbody = 0
endarm_x = 0
endarm_y = 0
headfunc(headtype,headcolor, headpensize)
bodyfunc(bodytype,bodycolor, bodypensize, endbody, endarm_x, endarm_y)
tailfunc(tail,endbody)
accessories1func(accessories1, endarm_x, endarm_y)
main()