[英]I can't seem to get my 2 eyes working for Turtle
So what am I missing here?那么我在这里错过了什么? I simply need to have 2 eyes that are filled in with the color red.
我只需要有两只用红色填充的眼睛。 I'm not sure what is missing for the "def eye", but I'm sure that's where I have made a mistake.
我不确定“def eye”缺少什么,但我确定那是我犯了错误的地方。
import turtle
t = turtle.Turtle()
def DCircle(x,y,radius,color):
t.penup()
t.setposition(x,y)
t.pendown()
t.fillcolor(color)
t.begin_fill()
t.color(color)
t.circle(radius)
t.end_fill()
def eye(color, radius):
t.penup()
t.setposition(-50,40)
t.pendown()
t.fillcolor(color)
t.color(red)
t.begin_fill()
t.circle(radius)
t.end_fill()
def Mickey():
r = 50
DCircle(0,0,2*r,'blue')
DCircle(-135,115,r,'red')
DCircle(135,115,r,'red')
def Main():
Mickey()
turtle.done()
turtle.bye()
turtle.getscreen()._root.mainloop()
Main()
I think you are trying to do this:我认为您正在尝试这样做:
import turtle
t = turtle.Turtle()
def DCircle(x,y,color,radius):
t.penup()
t.setposition(x,y)
t.pendown()
t.fillcolor(color)
t.begin_fill()
t.color(color)
t.circle(radius)
t.end_fill()
def Mickey():
r = 50
DCircle(0,0,'blue',2*r)
DCircle(-50,40,"red",r)
DCircle(50,40,"red",r)
def Main():
Mickey()
turtle.done()
turtle.bye()
turtle.getscreen()._root.mainloop()
Main()
You haven't positioned correctly!你没有正确定位! I think in your code you created
eye
function but never use that, but you don't need that function anyway.我认为在您的代码中您创建了
eye
功能但从未使用过它,但无论如何您都不需要该功能。 We can do anything circular in DCircle
function.我们可以在
DCircle
函数中做任何循环。
Edit : You can Mickey
function this then you will get as you say 2 eyes and 2 ears!编辑:您可以使用
Mickey
功能,然后您将得到 2 只眼睛和 2 只耳朵!
def Mickey():
r = 50
DCircle(0,0,2*r,'blue')
DCircle(-135,115,r,'red')
DCircle(135,115,r,'red')
DCircle(-50,100,20,"red")
DCircle(50,100,20,"red")
I don't think you need to make that eye
function!我认为你不需要做那个
eye
功能!
What's you are doing wrong in your code :你在代码中做错了什么:
t.color(red)
you can't write color name like this, color name should always be string! t.color(red)
有一个错误你不能像这样写颜色名称,颜色名称应该总是字符串!t.setposition(-50,40)
.t.setposition(-50,40)
硬编码了乌龟的位置。DCircle
function to do all these things, you have already made dynamic function to make any type of circle then, why you need to make new function and over complicate the things. DCircle
函数来完成所有这些事情,您已经制作了动态函数来制作任何类型的圆,那么为什么您需要制作新函数并且使事情变得过于复杂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.