我的新 Python 类(13 岁)需要一个阵亡将士纪念日事件。我们可以用 Turtle 绘制简单的形状;有谁知道画传统的两瓣罂粟的简单方法吗?谢谢!
最佳答案
Cardioid is closest to the shape of the poppies you buy to wear on Remembrance Day. ... You would need to draw 2 of them (one facing left to right and the other right to left) and then add a black circle ...
这看起来怎么样?它是几个通用心形线和一个排列成罂粟花形状的圆圈:
from turtle import Screen, Turtle
from math import pi, sin, cos
def cardioid(turtle, k):
origin_x, origin_y = turtle.position()
theta = 0.0
turtle.begin_fill()
while theta < 2.0 * pi:
x = 2 * k * (1 - cos(theta)) * cos(theta)
y = 2 * k * (1 - cos(theta)) * sin(theta)
turtle.goto(origin_x + x, origin_y + y)
theta += 0.1
turtle.end_fill()
screen = Screen()
yertle = Turtle(visible=False)
yertle.speed('fastest') # because I have no patience
yertle.color('red')
for sign in [-1, 1]:
yertle.penup()
yertle.setx(sign * 100)
yertle.pendown()
cardioid(yertle, sign * 30)
yertle.penup()
yertle.home()
yertle.dot(80, 'black')
screen.mainloop()
关于python - 在 Python 3 中绘制罂粟花,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52680750/