效果:
代码讲解:
首先导入模块。
from turtle import *
from math import *
获取桃心边上点的坐标。
def getXY(a,t):
x=a*(15*(sin(t)**3))
y=a*(15*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t))
return x,y
绘制桃心形函数
def draw():
pensize(3)
pencolor("red")
speed(0)
tracer(5)
pu()
a=8
t=0
while t<=360:
x,y=getXY(a,t)
goto(x,y)
pd()
dot(10)
t+=1
pu()
执行函数,最后保持窗口显示
draw()
done()
最终代码
from turtle import *
from math import *
def getXY(a,t):
x=a*(15*(sin(t)**3))
y=a*(15*cos(t)-5*cos(2*t)-2*cos(3*t)-cos(4*t))
return x,y
def draw():
pensize(3)
pencolor("red")
speed(0)
tracer(5)
pu()
a=8
t=0
while t<=360:
x,y=getXY(a,t)
goto(x,y)
pd()
dot(10)
t+=1
pu()
draw()
done()
喜欢的话就点赞关注吧!订阅Turtle画图专栏,查看更多往期文章吧!