给孩子们上课用的一个例子,先要讲一下函数与如何使用coloradd模块及安装方法。
import turtle from coloradd import colorset from winsound import PlaySound,SND_LOOP,SND_ASYNC def setcolor(): d = turtle.distance(0,0)+ 10 c = colorset(d) # 把整数转换成RGB颜色三元组 turtle.color(c) def draw_miao(step): for _ in range(7): setcolor() turtle.fd(step);turtle.dot(10,'red') turtle.rt(15) for _ in range(7): setcolor() turtle.lt(15) turtle.bk(step) for _ in range(7): setcolor() turtle.fd(step);turtle.dot(10,'red') turtle.lt(15) for _ in range(7): setcolor() turtle.rt(15) turtle.bk(step) turtle.delay(0) turtle.speed(0) turtle.pensize(1) turtle.colormode(255) turtle.bgcolor('black') PlaySound('11.wav',SND_LOOP|SND_ASYNC) for _ in range(45): draw_miao(30) turtle.rt(8) turtle.done()
发表评论