如何在Python Turtle上皱着眉头?

发布于 2025-01-18 22:59:40 字数 1045 浏览 1 评论 0原文

我需要用python制作皱着眉头的乌龟脸,但是我无法像皱眉那样获得半圆形弧,它太大或不完整。

import turtle
t = turtle.Turtle(2)
t.speed(5)
t.forward(120)
t.left(105)
t.forward(130)
t.right(90)
t.forward(25)
t.right(80)
t.forward(140)
t.left(65)
t.forward(100)
t.right(30)
t.forward(30)
t.right(30)
t.forward(30)
t.right(70)
t.forward(30)
t.right(30)
t.forward(30)
t.right (20)
t.forward(80)
t.left(65)
t.forward(130)
t.right(90)
t.forward(25)
t.right(80)
t.forward(110)
t.left (105)
t.forward (160)
t.left(65)
t.forward(50)
t.right(90)
t.forward(25)
t.right(80)
t.forward(60)
t.left (105)
t.right(65)
t.forward(70)
t.right(90)
t.forward(25)
t.right(80)
t.forward(32)
t.left (55)
t.forward(60)
t.penup()
t.right(90)
t.forward(20)
t.pendown()
r = 15
t.circle(r)
t.penup()
t.left(90)
t.forward(10)
t.left(90)
t.forward(5)
t.pendown()
r = 2
t.circle(r)
t.penup()
t.right(90)
t.forward(10)
t.pendown()
r = 2
t.circle(r)
t.penup()
t.forward(5)
t.right(90)
t.forward(15)
t.pendown()
for x in range(180):
    t.forward(1)
    t.right(1)
t.left(90)

到目前为止,这是我的代码

I need to make a frowning turtle face in python however I can't get the semi-circle arc like frown right, it's too big or not complete.

import turtle
t = turtle.Turtle(2)
t.speed(5)
t.forward(120)
t.left(105)
t.forward(130)
t.right(90)
t.forward(25)
t.right(80)
t.forward(140)
t.left(65)
t.forward(100)
t.right(30)
t.forward(30)
t.right(30)
t.forward(30)
t.right(70)
t.forward(30)
t.right(30)
t.forward(30)
t.right (20)
t.forward(80)
t.left(65)
t.forward(130)
t.right(90)
t.forward(25)
t.right(80)
t.forward(110)
t.left (105)
t.forward (160)
t.left(65)
t.forward(50)
t.right(90)
t.forward(25)
t.right(80)
t.forward(60)
t.left (105)
t.right(65)
t.forward(70)
t.right(90)
t.forward(25)
t.right(80)
t.forward(32)
t.left (55)
t.forward(60)
t.penup()
t.right(90)
t.forward(20)
t.pendown()
r = 15
t.circle(r)
t.penup()
t.left(90)
t.forward(10)
t.left(90)
t.forward(5)
t.pendown()
r = 2
t.circle(r)
t.penup()
t.right(90)
t.forward(10)
t.pendown()
r = 2
t.circle(r)
t.penup()
t.forward(5)
t.right(90)
t.forward(15)
t.pendown()
for x in range(180):
    t.forward(1)
    t.right(1)
t.left(90)

This is my code so far

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

心意如水 2025-01-25 22:59:40

我们可以再次使用circle()方法来皱眉,而不是使用显式循环。在这种情况下,我们需要添加可选的latect参数,还可以了解使用正和负射线和分量的方法circle()

以下是我的示例解决方案,我将最初的飞机图纸扔到,只是专注于面部:

import turtle

t = turtle.Turtle()

# head
r = 15
t.right(90)
t.circle(r)

r = 2

# right eye
t.penup()
t.left(90)
t.forward(10)
t.left(90)
t.forward(5)
t.pendown()
t.circle(r)

# left eye
t.penup()
t.right(90)
t.forward(10)
t.right(90)
t.pendown()
t.circle(r)

# frown
r = 5
t.penup()
t.left(90)
t.backward(5)
t.right(90)
t.forward(10)
t.left(90)
t.circle(-r, 60)
t.pendown()
t.circle(-r, -120)

t.hideturtle()
turtle.done()

Rather than using an explicit loop, we can use the circle() method again to draw the frown. In this case we need to add the optional extent argument, and also learn what using positive and negative radii and extents does to circle().

Below is my example solution where I've tossed your initial airplane drawing just to focus on the face:

import turtle

t = turtle.Turtle()

# head
r = 15
t.right(90)
t.circle(r)

r = 2

# right eye
t.penup()
t.left(90)
t.forward(10)
t.left(90)
t.forward(5)
t.pendown()
t.circle(r)

# left eye
t.penup()
t.right(90)
t.forward(10)
t.right(90)
t.pendown()
t.circle(r)

# frown
r = 5
t.penup()
t.left(90)
t.backward(5)
t.right(90)
t.forward(10)
t.left(90)
t.circle(-r, 60)
t.pendown()
t.circle(-r, -120)

t.hideturtle()
turtle.done()
七婞 2025-01-25 22:59:40

您可以使用Turtle.circle(半径,弧度)进行半圆形。
例如:

turtle.circle(50 , 180)

这将使半径为50px的半圆。您可以相应地改变乌龟的方向,以使弧面朝下。

You can use turtle.circle(radius , extent of arc) to make a semi-circle.
For example:

turtle.circle(50 , 180)

This would make a semi circle of radius 50px. You can change the direction of the turtle accordingly to make the arc face down.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文