python - 在 Python 3 中绘制罂粟花

标签 python drawing turtle-graphics

我的新 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()

enter image description here

关于python - 在 Python 3 中绘制罂粟花,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52680750/

相关文章:

python - 带选定点的 3D 线图

python - 有没有人为 vim 找到了一套好的 python 插件——特别是模块完成?

python - 比较python中两个数组的值

android - 使用坐标系在android屏幕上绘图

python - python 中的 turtle - 试图让 turtle 移动到鼠标点击位置并打印其坐标

python - 如何将非 ASCII 字符编码的文件重命名为 ASCII

c# - 如何在 Canvas 上快速重画。 C# WINFORM

actionscript-3 - AS3 : removing a lineStyle in the middle of drawing a shape

python - 使用 turtle 图形以奇数顺序执行代码

Python turtle.setup() 将 Canvas 截断为屏幕大小——如何避免这种情况?