gpt4 book ai didi

python - 螺旋图 turtle 蟒

转载 作者:行者123 更新时间:2023-11-28 22:53:51 25 4
gpt4 key购买 nike

如何玩 turtle ,如何使用 turtle ?

我无法像下图所示那样工作(忽略颜色)。

Image

from turtle import *
from math import *


def formulaX(R, r, p, t):
x = (R-r)*cos(t) - (r + p)*cos((R-r)/r*t)

def formulaY(R, r, p, t):
y = (R-r)*sin(t) - (r + p)*sin((R-r)/r*t)

def t_iterating(R, r, p):
t = 2*pi
up()
goto(formulaX, formulaY)
down()

while (True):
t = t + 0.01
formulaX(R, r, p, t)
formulaY(R, r, p, t)


def main():
R = int(input("The radius of the fixed circle: "))
r = int(input("The radius of the moving circle: "))
p = int(input("The offset of the pen point, between <10 - 100>: "))

if p < 10 or p > 100:
input("Incorrect value for p!")

t_iterating(R, r, p)

input("Hit enter to close...")

main()'

我正在尝试制作那种形状。这是我到目前为止完成的编码。

最佳答案

尝试将您的 t_iterating 函数更改为:

def t_iterating(R, r, p):
t = 2*pi # It seems odd to me to start from 2*pi rather than 0.
down()

while t < 20*pi: # This loops while t goes from 2*pi to 20*pi.
t = t+0.01
goto(formulaX(R, r, p, t), formulaY(R, r, p, t))
up()

关于python - 螺旋图 turtle 蟒,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18936731/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com