gpt4 book ai didi

python - 在 Python 3 中绘制罂粟花

转载 作者:太空宇宙 更新时间:2023-11-03 21:43:21 24 4
gpt4 key购买 nike

我的新 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/

24 4 0
文章推荐: html - 将最后一个
  • float 到
  • 文章推荐: javascript - elim 单击了
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com