
在微信上看到一个未完成的小猪佩奇,使用 python 内置的 turtle 绘制,代码是我整理完善的,直接献上。
# coding:utf-8
import turtle as tur
def nose(x,y):#鼻子
tur.penup()#提起笔
<(x,y)#定位tur.pendown()#落笔,开始画
tur.setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)
tur.begin_fill()#准备开始填充图形
a=0.4
for i in range(120):
if 0<=i<30 or 60<=i<90:
a=a+0.08
tur.left(3) #向左转3度
tur.forward(a) #向前走a的步长
else:
a=a-0.08
tur.left(3)
tur.forward(a)
tur.penup()
tur.setheading(90)
tur.forward(25)
tur.setheading(0)
tur.forward(10)
tur.pendown()
tur.pencolor(255,155,192)#画笔颜色
tur.setheading(10)
tur.begin_fill()
tur.circle(5)
tur.penup()
tur.setheading(0)
tur.forward(20)
tur.pendown()
tur.pencolor(255,155,192)
tur.setheading(10)
tur.begin_fill()
tur.circle(5)
def head(x,y):#头
tur.penup()
<(x,y)tur.setheading(0)
tur.pendown()
tur.begin_fill()
tur.setheading(180)
tur.circle(300,-30)
tur.circle(100,-60)
tur.circle(80,-100)
tur.circle(150,-20)
tur.circle(60,-95)
tur.setheading(161)
tur.circle(-300,15)
tur.penup()
<(-100,100)tur.pendown()
tur.setheading(-30)
a=0.4
for i in range(60):
if 0<=i<30 or 60<=i<90:
a=a+0.08
tur.lt(3) #向左转3度
tur.forward(a) #向前走a的步长
else:
a=a-0.08
tur.lt(3)
tur.forward(a)
def ears(x,y): #耳朵
tur.penup()
<(x,y)tur.pendown()
tur.begin_fill()
tur.setheading(100)
tur.circle(-50,50)
tur.circle(-10,120)
tur.circle(-50,54)
tur.penup()
tur.setheading(90)
tur.forward(-12)
tur.setheading(0)
tur.forward(30)
tur.pendown()
tur.begin_fill()
tur.setheading(100)
tur.circle(-50,50)
tur.circle(-10,120)
tur.circle(-50,56)
def eyes(x,y):#眼睛
tur.penup()
tur.setheading(90)
tur.forward(-20)
tur.setheading(0)
tur.forward(-95)
tur.pendown()
tur.begin_fill()
tur.circle(15)
tur.penup()
tur.setheading(90)
tur.forward(12)
tur.setheading(0)
tur.forward(-3)
tur.pendown()
tur.begin_fill()
tur.circle(3)
tur.penup()
tur.seth(90)
tur.forward(-25)
tur.seth(0)
tur.forward(40)
tur.pendown()
tur.begin_fill()
tur.circle(15)
tur.penup()
tur.setheading(90)
tur.forward(12)
tur.setheading(0)
tur.forward(-3)
tur.pendown()
tur.begin_fill()
tur.circle(3)
def cheek(x,y):#腮
tur.penup()
<(x,y)tur.pendown()
tur.setheading(0)
tur.begin_fill()
tur.circle(30)
def mouth(x,y): #嘴
tur.penup()
<(x,y)tur.pendown()
tur.setheading(-80)
tur.circle(30,40)
tur.circle(40,80)
def body(x,y): #身子
tur. color("red", (255, 99, 71))
tur. penup()
tur. goto(x,y)
tur. pendown()
tur. begin_fill()
tur. seth(-130)
tur. circle(100, 10)
tur. circle(300, 30)
tur. seth(0)
tur. forward(230)
tur. seth(90)
tur. circle(300, 30)
tur. circle(100, 3)
tur. color((255, 155, 192), (255, 100, 100))
tur. seth(-135)
tur. circle(-80, 63)
tur. circle(-150, 24)
tur. end_fill()
def hands(x,y): #手
tur. color((255, 155, 192))
tur. penup()
tur. seth(90)
tur. forward(-40)
tur. seth(0)
tur. forward(-27)
tur. pendown()
tur. seth(-160)
tur. circle(300, 15)
tur. penup()
tur. seth(90)
tur. forward(15)
tur. seth(0)
tur. forward(0)
tur. pendown()
tur. seth(-10)
tur. circle(-20, 90)
tur. penup()
tur. seth(90)
tur. forward(30)
tur. seth(0)
tur. forward(237)
tur. pendown()
tur. seth(-20)
tur. circle(-300, 15)
tur. penup()
tur. seth(90)
tur. forward(20)
tur. seth(0)
tur. forward(0)
tur. pendown()
tur. seth(-170)
tur. circle(20, 90)
def feet(x,y): #脚
tur. pensize(10)
tur. color((240, 128, 128))
tur. penup()
tur. seth(90)
tur. forward(-75)
tur. seth(0)
tur. forward(-180)
tur. pendown()
tur. seth(-90)
tur. forward(40)
tur. seth(-180)
tur. color("black")
tur. pensize(15)
tur. forward(20)
tur. pensize(10)
tur. color((240, 128, 128))
tur. penup()
tur. seth(90)
tur. forward(40)
tur. seth(0)
tur. forward(90)
tur. pendown()
tur. seth(-90)
tur. forward(40)
tur. seth(-180)
tur. color("black")
tur. pensize(15)
tur. forward(20)
def tail(x,y): #尾巴
tur. pensize(4)
tur. color((255, 155, 192))
tur. penup()
tur. seth(90)
tur. forward(70)
tur. seth(0)
tur. forward(95)
tur. pendown()
tur. seth(0)
tur. circle(70, 20)
tur. circle(10, 330)
tur. circle(70, 30)
def setting(): #参数设置
tur.pensize(4)
tur.hideturtle() #使乌龟无形(隐藏)
tur.setup(840,500)
tur.speed(10)
def main():
setting() #画布、画笔设置
nose(-100,100) #鼻子
head(-69,167) #头
ears(0,160) #耳朵
eyes(0,0) #眼睛
cheek(80,10) #腮
mouth(-20,30) #嘴
body(-32,-8)
hands(0,0)
feet(0,0)
tail(0,0)
tur.done()
if __name__ == '__main__':
main()
本文发布于:2024-03-05 00:22:41,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/1709614160120721.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
| 留言与评论(共有 0 条评论) |