用Python画小猪佩奇
图片
代码
# coding:utf-8
import turtle as tu
tu.pensize(4) # 设置画笔的大小
tu.colormode(255) # 设置GBK颜色范围为0-255
tu.color((255, 155, 192), "pink") # 设置画笔颜色和填充颜色(pink)tu.setup(850, 500)
# 画鼻子部tu.pu() # 提笔tu.goto(-100, 100) # 画笔前往坐标(-100,100)tu.pd() # 下笔tu.seth(-30) # 笔的角度为-30°tu.begin_fill() # 外形填充的开始标志
a = 0.4
for i in range(120):
if 0 <= i < 30 or 60 <= i < 90:
a = a + 0.08hhd
tu.lt(3) # 向左转3度
tu.fd(a) # 向前走a的步长
else:
a = a - 0.08
tu.lt(3)
tu.fd(a)
tu.end_fill() # 依据轮廓填充
tu.pu() # 提笔
tu.seth(90) # 笔的角度为90度
tu.fd(25) # 向前移动25
tu.seth(0) # 转换画笔的角度为0
tu.fd(10)
tu.pd()
tu.pencolor(255, 155, 192) # 设置画笔颜色
tu.seth(10)
tu.begin_fill()
tu.circle(5) # 画一个半径为5的圆
tu.color(160, 82, 45) # 设置画笔和填充颜色
tu.end_fill()
tu.pu()
tu.seth(0)
tu.fd(20)
tu.pd()
tu.pencolor(255, 155, 192)
tu.seth(10)
tu.begin_fill()
tu.circle(5)
tu.color(160, 82, 45)
tu.end_fill()
# 画头部
tu.color((255, 155, 192), "pink")
tu.pu()
tu.seth(90)
tu.fd(41)<