Python_Turtle绘制余弦函数(采用一维线描法绘制二维平面)(turtle实现)
【注1】采用线动成面的原理,使用一维线去绘制二维平面图形!
【注2】密集的描竖直线即可!
1.LineToFaceCos.py
import turtle as tle
import math
tle.speed(0)
tle.delay(0)
tle.pensize(1)
tle.pencolor("blue")
tle.tracer(True)
#tle.tracer(False)
col = ["blue","green"]
def subline(x,coll,y=[]):
tle.pencolor(coll)
tle.penup()
tle.goto(x,-220)
tle.pendown()
for i in y:
tle.goto(x,i-2)
tle.penup()
tle.goto(x,i+2)
tle.pendown()
tle.goto(x,220)
k = 0
i = -150
while(i<=150):
if k == 2:
k = 0
i = i + 1
y = []
y.append(70*math.cos(0.06*i+4)+20)
subline(i,col[k],y)
k = k + 1
tle.done()