coloradd模块主要用来配合海龟画图,能使所画的图形更加漂亮。
本源代码为coloradd模块学习代码,请认真查看saturationset和lightset和coloradd与colorset的用法
saturationset: 饱和度设置,lightset:亮度设置,coloradd:颜色增加,colorset颜色设置。
import turtle from coloradd import * ft = ("",12,"normal") screen = turtle.getscreen() screen.colormode(255) screen.delay(0) screen.bgcolor('black') screen.title("draw lollipop 画棒棒糖") c = (255,0,0) # RGB红色 turtle.ht() # 隐藏海龟 turtle.penup() # 抬起笔来 turtle.goto(0,100) # 定位坐标 turtle.pendown() # 落下画笔 for i in range(300): # 迭代变量 turtle.width(i/10) # 画笔笔宽 turtle.fd(i/10) # 海龟前进 turtle.rt(10) # 海龟右转 c = coloradd(c,0.01) # 颜色增加 turtle.pencolor(c) # 画笔颜色 turtle.penup() # 抬起笔来 turtle.goto(0,100) # 定位坐标 turtle.setheading(-90) # 方向向下 turtle.color("brown") # 画笔颜色 turtle.pendown() # 落下笔来 turtle.fd(280) # 前进300 turtle.penup() # 抬起笔来 turtle.color("gray") # 画笔颜色 turtle.write("www.lixingqiu.com",align='center',font=ft) # 亮度设置 turtle.goto(-300,-200) turtle.write("lightset test (亮度测试)",font=ft) turtle.goto(-300,-230) c = (255,0,0) turtle.setheading(0) turtle.pendown() for x in range(200): ys = lightset(c,x/200) # 设置红色的亮度 turtle.color(ys) turtle.fd(3) turtle.penup() # 饱和度设置 turtle.goto(-300,-280) turtle.write("saturation test (饱和度测试)",font=ft) turtle.goto(-300,-300) c = (255,0,0) turtle.setheading(0) turtle.pendown() for x in range(200): ys = saturationset(c,x/200) # 设置红色的饱和度 turtle.color(ys) turtle.fd(3) screen.mainloop()