【python代码】math与turtle库之蝴蝶曲线的运用
几个turtle库基本函数:
1:turtle.pensize(x) :X大小控制画笔大小
2:turtle.pencolor(“color”):画笔颜色控制,color为想要输入的颜色名称
引入turtle库跟math库:
from turtle import*
from math import*
几个math函数:
exp(x):表示为e的x次方
pow(x,y):表示为x的y次方
[python] math与turtle库之蝴蝶曲线代码:
from turtle import *
from math import *
pensize(3)
pencolor("red") #画笔颜色
def draw(a,end):
t=0
while t<24*end:
x=a*sin(t)*(exp(cos(t))-2*cos(4*t)+pow(sin(t/12),5))
y=a*cos(t)*(exp(cos(t))-2*cos(4*t)+pow(sin(t/12),5))
goto(x,y)
t=t+0.05
if __name__ == '__main__':
draw(60,pi)