Python_Turtle绘制[椭圆]函数(采用一维线描法绘制二维平面)(turtle实现)
【下篇预告】面动成体画法,由二维平面绘制三维立体!
【注1】采用线动成面的原理,使用一维线去绘制二维平面图形!
【注2】密集的描竖直线即可!【线动成面最后一篇!】
【注3】在一维竖直线上有多点在函数上!即一个x对应多个y值,则先将多个y值求解放在列表y中!
1.LineToFaceTuoCircle.py
import turtle as tle
import math
tle.speed(0)
tle.delay(0)
tle.pensize(2)
tle.pencolor("blue")
tle.tracer(True)
#tle.tracer(False)
col = ["gray"]
def subline(x,coll,y=[]):
tle.pencolor(coll)
tle.penup()
tle.goto(x,-220)
tle.pendown()
for i in y:
if x >= -150 and x <-60:
tle.goto(x,i-1.4)
#tle.penup()
tle.pencolor("red")
tle.goto(x,i+1.4)
tle.pencolor(coll)
#tle.pendown()
elif x >= -60 and x <= 0:
tle.goto(x,i-0.8)
#tle.penup()
tle.pencolor("yellow")
tle.goto(x,i+0.8)
tle.pencolor(coll)
#tle.pendown()
if x > 0 and x <= 60:
tle.goto(x,i-0.8)
#tle.penup()
tle.pencolor("orange")
tle.goto(x,i+0.8)
tle.pencolor(coll)
#tle.pendown()
elif x >= 60 and x <= 150:
tle.goto(x,i-1.4)
#tle.penup()
tle.pencolor("skyblue")
tle.goto(x,i+1.4)
tle.pencolor(coll)
#tle.pendown()
tle.goto(x,220)
k = 0
i = -150
while(i<=150):
if k == 1:
k = 0
y = []
if i == 150 or i == -150:
y.append(math.sqrt(2500-i*i*(1/9)))
else:
y.append(-math.sqrt(2500-i*i*(1/9)))
y.append(math.sqrt(2500-i*i*(1/9)))
subline(i,col[k],y)
i = i + 1
k = k + 1
tle.done()