Python Turtle 绘制蝴蝶曲线

Python Turtle 绘制蝴蝶曲线_第1张图片

 这次我们用Turtle绘制上图的蝴蝶曲线

我们需要进行多次循环得出每个点的坐标,最后这些点连接成了上图曲线

公式有点复杂。。。。。如下:

x=a\cdot\sin t\cdot [e^{\cos t}-2\cos 4t+(\sin \frac{t}{12})^{5}]

y=b\cdot \cos t\cdot [e^{\cos t}-2\cos 4t+(\sin\frac{t}{12})^{5}]

用Python程序实现

from turtle import *
from math import sin,cos,e

def draw():
    cycle=25
    t=0
    while not (t>cycle*360):
        p=e**cos(t)-2*cos(4*t)+sin(t/12)**5
        x=a*sin(t)*p
        y=b*cos(t)*p
        goto(x,y)
        dot()
        t+=1
        print(t)


pencolor("red")
pu()
speed(0)
tracer(1000)
a=b=40

draw()

ht()
done()

 


喜欢就赞一下吧~

你可能感兴趣的:(python)