
这函数学习与练习课例子。需要安装coloradd模块。
用cmd命令,打开管理员窗口,输入pip install coloradd即可安装这个模块。
colorset命令能把整数变成一个RGB三元组。方便以原点为中心的颜色对称效果。
import turtle
from coloradd import colorset
def setcolor():
d = turtle.distance(0,0)+ 10
c = colorset(d)
turtle.color(c)
def draw_square(length):
for _ in range(4):
turtle.fd(length)
turtle.rt(90)
def draw_branch():
turtle.fd(40)
for i in range(4):
setcolor()
turtle.fd(40)
if i==3:
setcolor()
turtle.left(90)
turtle.circle(-10)
turtle.right(90)
else:
draw_square(8)
turtle.delay(0)
turtle.speed(0)
turtle.pensize(1)
turtle.colormode(255)
turtle.bgcolor('black')
for _ in range(45):
draw_branch()
turtle.bk(200)
turtle.rt(8)
turtle.done()
