Python 如何在 Turtle 中制作笑脸?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/26500332/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make a smiley face in Turtle?
提问by
First time ever using Turtle. My assignment is to make a smiley face, any size and any position. I just can't get the mouth right because I really don't know what I'm doing. I've read quite a bit and what I want to do is after the right smile, start and (0,0) and just make a mirror image of it. Thanks for any help.
第一次使用 Turtle。我的任务是制作一张笑脸,任何尺寸和任何位置。我就是说不出口,因为我真的不知道我在做什么。我已经阅读了很多,我想要做的是在正确的微笑之后,开始和 (0,0) 并制作它的镜像。谢谢你的帮助。
import turtle
wn = turtle.Screen()
smiles = turtle.Turtle()
smiles.penup()
smiles.goto(-75,150)
smiles.pendown()
smiles.circle(10) #eye one
smiles.penup()
smiles.goto(75,150)
smiles.pendown()
smiles.circle(10) #eye two
smiles.penup()
smiles.goto(0,0)
smiles.pendown()
smiles.circle(100,90) #right smile
smiles.penup() #below is where i feel i'm messing up
smiles.goto(0,0)
smiles.pendown()
smiles.circle(-100,90)
回答by Bill Letson
Turtle keeps track of its orientation when it does a partial circle. Insert this line:
海龟在做部分圆时会跟踪它的方向。插入这一行:
smiles.penup() #below is where i feel i'm messing up
smiles.circle(0, 270) # New line here
smiles.goto(0,0)
smiles.pendown()
smiles.circle(-100,90)
to spin it around to start a new circle.
旋转它开始一个新的圈子。
回答by jfs
You could call setheading(180)to make the turtle look West:
你可以打电话setheading(180)让乌龟看向西:
import turtle
smiles = turtle.Turtle()
smiles.penup()
smiles.goto(-75,150)
smiles.pendown()
smiles.circle(10) #eye one
smiles.penup()
smiles.goto(75,150)
smiles.pendown()
smiles.circle(10) #eye two
smiles.penup()
smiles.goto(0,0)
smiles.pendown()
smiles.circle(100,90) #right smile
smiles.penup()
smiles.setheading(180) # <-- look West
smiles.goto(0,0)
smiles.pendown()
smiles.circle(-100,90)


You could try it online e.g. http://www.skulpt.org
您可以在线试用,例如http://www.skulpt.org
回答by hello
def smileyface(): penup() goto(-75,150) pendown() circle(10)
def 笑脸(): penup() goto(-75,150) pendown() circle(10)
penup()
goto(75,150)
pendown()
circle(10)
penup()
goto(0,0)
pendown()
circle(100,90)
penup()
goto(0,0)
pendown()
circle(-100,90)

