今天闲来无事,用turtle画了个小猪佩奇,代码其实很简单的,就是烦了点。
没必要每行代码都发出来,给大家看几个主要的函数好了。
另外我给绝大多数代码都加上了注释,相同的代码我就不加了。首先需要初始化画笔的一些属性,包括颜色、画笔的画画速度等。
def init_pen():
'''
初始化画笔的一些属性
'''
t.pensize(4) # 设置画笔的大小
t.colormode(255) # 设置GBK颜色范围为0-255
t.color((255, 155, 192), "pink") # 设置画笔颜色和填充颜色(pink)
t.setup(900, 500) # 设置主窗口的大小为900*500
t.speed(10) # 设置画笔速度为10
其次就是画各个部位了,比如鼻子:
def norse():
'''
鼻子
'''
t.pu() # 提笔
t.goto(-100, 100) # 画笔前往坐标(-100,100)
t.pd() # 下笔
t.seth(-30) # 笔的角度为-30°
t.begin_fill() # 外形填充的开始标志
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08
t.lt(3) # 向左转3度
t.fd(a) # 向前走a的步长
else:
a = a - 0.08
t.lt(3)
t.fd(a)
t.end_fill() # 依据轮廓填充
t.pu() # 提笔
t.seth(90) # 笔的角度为90度
t.fd(25) # 向前移动25
t.seth(0) # 转换画笔的角度为0
t.fd(10)
t.pd()
t.pencolor(255, 155, 192) # 设置画笔颜色
t.seth(10)
t.begin_fill()
t.circle(5) # 画一个半径为5的圆
t.color(160, 82, 45) # 设置画笔和填充颜色
t.end_fill()
t.pu()
t.seth(0)
t.fd(20)
t.pd()
t.pencolor(255, 155, 192)
t.seth(10)
t.begin_fill()
t.circle(5)
t.color(160, 82, 45)
t.end_fill()
其余部位的代码就不给大家一一展示啦,太长了。那么最后看下效果图吧~
热 文 推 荐
☞STO不会火,比特大陆不会死,币安会去非洲:区块链行业的63个预测
☞刚刚!程序员集体荣获2个冠军,这份2018 IT报告还说这些!
print_r('点个好看吧!');
var_dump('点个好看吧!');
NSLog(@"点个好看吧!");
System.out.println("点个好看吧!");
console.log("点个好看吧!");
print("点个好看吧!");
printf("点个好看吧!");
cout << "点个好看吧!" << endl;
Console.WriteLine("点个好看吧!");
fmt.Println("点个好看吧!");
Response.Write("点个好看吧!");
alert("点个好看吧!")
echo "点个好看吧!"
点击“阅读原文”,打开 CSDN App 阅读更贴心!
![640?wx_fmt=png](https://i-blog.csdnimg.cn/blog_migrate/4b2b95350a1aa373154a340982983484.png)