在 Python 中画一朵罂粟花 3

Draw a Poppy in Python 3

我的新 Python class(13 岁)需要一个纪念日 activity。我们可以用 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()