学习笔记_py_Q版蛇
来源:互联网 发布:java实现线程安全 编辑:程序博客网 时间:2024/06/05 18:47
import turtle#from turtle import *def drawSnake(rad, angle, len, neckrad):#定义弧度,角度,长度,蛇脖子头的角度 for i in range(len):#i 到 长度 turtle.circle(rad, angle)#圆的,弧度,角度 turtle.circle(-rad, angle)#圆的负弧度,角度, turtle.circle(rad, angle/2)#圆的弧度,1/2角度 turtle.fd(rad)#弧度?有点迷茫,表示forward距离 turtle.circle(neckrad+1, 180)#脖子头弧度+1, turtle.fd(rad* 2/3)#2/3弧度def main(): turtle.setup(1300, 800, 0, 0)#窗口长1300,宽800,起始坐标0,0 pythonsize = 30#笔触30 turtle.pensize(pythonsize)#笔触30 turtle.pencolor("blue")#初始色蓝色 turtle.seth(-40)#,起始的角度 drawSnake(40, 80, 5, pythonsize/2)#弧度半径40?角度80,长度5,脖子头30/2=15main()
import turtle#from turtle import *turtle.speed(10)#速度10,还有一种turtle.tracer(False),可以更快def drawSnake(rad, angle, len, neckrad):#定义弧度,角度,长度,蛇脖子头的角度 global color#全局变量颜色 color = 0x1000FF#初始的颜色,一种接近蓝黑的颜色 lastrad = rad*2//3#弧度×2整除3 halfangle = angle//2#角度整除2 for i in range(len):#i 到 长度 for i in range(angle):#i 到角度 turtle.circle(rad, 1)#圆的弧度,1段 colorchange()#拿颜色 for j in range(angle):#从j到角度 turtle.circle(-rad, 1)#圆的负弧度,1段 colorchange()#拿颜色 for j in range(halfangle):#从j到半角度 turtle.circle(rad, 1)#圆的弧度,1段 colorchange()#拿颜色 for j in range(rad):#从j到弧度 turtle.fd(1)#向前1 colorchange()#拿颜色 for j in range(180):#从J到180 turtle.circle(neckrad+1,1)#圆的弧度,1段 colorchange()#拿颜色 for j in range(lastrad):#j到lastrad,lastrad在上面定义了 turtle.fd(1)#向前1 colorchange()#拿颜色 def colorchange():#定义拿颜色 global color#全局变量颜色 x = 0xEF#一个十六进制的数, change = 0x010000#初始颜色 coefficient = 0xEF0000#一种颜色,大概是最后颜色,大概为50% color = hex(color+x+change)#利用十六进制变色 judge = color[2:4]#好吧,我不太懂了,百度了下,意思大概是引索2到4,不包括4的数 number = color[2:]#大概是2到无穷,不包括无穷,大概为20% colorcode = '#'+number#不知道,没搜到,我猜的意思是颜色数值编码的意思,我记得颜色编码前面有个#,好吧,就是这样的 turtle.pencolor(colorcode)#笔触的颜色编码 color = int(color,16)#赋予? if judge == 'ff':#判断十六进制最后两位是否为ff,大概为20% color -= coefficient#颜色慢慢变浅def main(): turtle.setup(1300, 800, 0, 0)#窗口长1300,宽800,起始坐标0,0 pythonsize = 30#笔触30 turtle.pensize(pythonsize)#笔触30 turtle.pencolor("blue")#初始色蓝色 turtle.seth(-40)#,起始的角度 drawSnake(40, 80, 5, pythonsize/2)#弧度半径40?角度80,长度5,脖子头30/2=15main()
阅读全文