用python的 turtle 怎么画这个曲线? python颜色填充turtle
- python Turtle如何绘制任意弧度的曲线?
- 怎么用python中的turtle画希尔伯特曲线
- 用python中的turtle画希尔伯特曲线该怎么写
- 如何和采用Python语言在turtle工具画散点
python Turtle如何绘制任意弧度的曲线?
要画弧线自然需要用到正余弦函数
怎么用python中的turtle画希尔伯特曲线
代码如下:
import sys, math, time
import turtle
count = 0
def moveto(x,y):
turtle.penup()
turtle.goto(x,y)
turtle.pendown()
def hilbert(x0, y0, xi, xk, yi, yk, n):
if n <= 0:
X = x0 + (xi + yi)/2
Y = y0 + (xk + yk)/2
X2 = X * 600 -300
Y2 = Y * 600 -300
global count
if count < 1:
count = count + 1
moveto(X2,Y2)
turtle.color(X,Y,X*Y)
turtle.goto(X2,Y2)
else:
hilbert(x0, y0, yi/2, yk/2, xi/2, xk/2, n - 1)
hilbert(x0 + xi/2, y0 + xk/2, xi/2, xk/2, yi/2, yk/2, n - 1)
hilbert(x0 + xi/2 + yi/2, y0 + xk/2 + yk/2, xi/2, xk/2, yi/2, yk/2, n - 1)
hilbert(x0 + xi/2 + yi, y0 + xk/2 + yk, -yi/2,-yk/2,-xi/2,-xk/2, n - 1)
def main():
turtle.colormode(1.)
turtle.speed(0)
for depth in range(9):
if 7 > depth > 4: # for faster rendering.
turtle.getscreen().tracer(0)
global count
count = 0
hilbert(0.0, 0.0, 1.0, 0.0, 0.0, 1.0, depth)
turtle.getscreen().tracer(1)
time.sleep(2)
turtle.Screen().exitonclick()
if __name__ == "__main__":
main()
用python中的turtle画希尔伯特曲线该怎么写
代码如下,记得采纳:
import sys, math, time
import turtle
count = 0
def moveto(x,y):
turtle.penup()
turtle.goto(x,y)
turtle.pendown()
def hilbert(x0, y0, xi, xk, yi, yk, n):
if n <= 0:
X = x0 + (xi + yi)/2
Y = y0 + (xk + yk)/2
X2 = X * 600 -300
Y2 = Y * 600 -300
global count
if count < 1:
count = count + 1
moveto(X2,Y2)
turtle.color(X,Y,X*Y)
turtle.goto(X2,Y2)
else:
hilbert(x0, y0, yi/2, yk/2, xi/2, xk/2, n - 1)
hilbert(x0 + xi/2, y0 + xk/2, xi/2, xk/2, yi/2, yk/2, n - 1)
hilbert(x0 + xi/2 + yi/2, y0 + xk/2 + yk/2, xi/2, xk/2, yi/2, yk/2, n - 1)
hilbert(x0 + xi/2 + yi, y0 + xk/2 + yk, -yi/2,-yk/2,-xi/2,-xk/2, n - 1)
def main():
turtle.colormode(1.)
turtle.speed(0)
for depth in range(9):
if 7 > depth > 4: # for faster rendering.
turtle.getscreen().tracer(0)
global count
count = 0
hilbert(0.0, 0.0, 1.0, 0.0, 0.0, 1.0, depth)
turtle.getscreen().tracer(1)
time.sleep(2)
turtle.Screen().exitonclick()
if __name__ == "__main__":
main()
如何和采用Python语言在turtle工具画散点
因为你改的只是画笔的颜色。、
aturtle.begin_fill()
aturtle.fillcolor('yellow')
dosomethinghere()
aturtle.end_fill()
用这个就好了。(aturtle是这个turtle对象的名字,改成自己的就好了。颜色自己选,yellow那里。)填色不一样。如果水平很基础可以试试small basics。基本上turtle的理念都是通用的。
找到好的带向导的idle学习比较简单,不过基础会薄弱一点。