用python画小猪佩奇动画片全集

编程入门 行业动态 更新时间:2024-10-15 02:26:29

用python画<a href=https://www.elefans.com/category/jswz/34/1724932.html style=小猪佩奇动画片全集"/>

用python画小猪佩奇动画片全集

在微信上看到一个未完成的小猪佩奇,使用 python 内置的 turtle 绘制,代码是我整理完善的,直接献上。

# coding:utf-8

import turtle as tur

def nose(x,y):#鼻子

tur.penup()#提起笔

tur.goto(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.end_fill()#填充完成

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.color(160,82,45)#返回或设置pencolor和fillcolor

tur.end_fill()

tur.penup()

tur.setheading(0)

tur.forward(20)

tur.pendown()

tur.pencolor(255,155,192)

tur.setheading(10)

tur.begin_fill()

tur.circle(5)

tur.color(160,82,45)

tur.end_fill()

def head(x,y):#头

tur.color((255,155,192),"pink")

tur.penup()

tur.goto(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()

tur.goto(-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)

tur.end_fill()

def ears(x,y): #耳朵

tur.color((255,155,192),"pink")

tur.penup()

tur.goto(x,y)

tur.pendown()

tur.begin_fill()

tur.setheading(100)

tur.circle(-50,50)

tur.circle(-10,120)

tur.circle(-50,54)

tur.end_fill()

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)

tur.end_fill()

def eyes(x,y):#眼睛

tur.color((255,155,192),"white")

tur.penup()

tur.setheading(90)

tur.forward(-20)

tur.setheading(0)

tur.forward(-95)

tur.pendown()

tur.begin_fill()

tur.circle(15)

tur.end_fill()

tur.color("black")

tur.penup()

tur.setheading(90)

tur.forward(12)

tur.setheading(0)

tur.forward(-3)

tur.pendown()

tur.begin_fill()

tur.circle(3)

tur.end_fill()

tur.color((255,155,192),"white")

tur.penup()

tur.seth(90)

tur.forward(-25)

tur.seth(0)

tur.forward(40)

tur.pendown()

tur.begin_fill()

tur.circle(15)

tur.end_fill()

tur.color("black")

tur.penup()

tur.setheading(90)

tur.forward(12)

tur.setheading(0)

tur.forward(-3)

tur.pendown()

tur.begin_fill()

tur.circle(3)

tur.end_fill()

def cheek(x,y):#腮

tur.color((255,155,192))

tur.penup()

tur.goto(x,y)

tur.pendown()

tur.setheading(0)

tur.begin_fill()

tur.circle(30)

tur.end_fill()

def mouth(x,y): #嘴

tur.color(239,69,19)

tur.penup()

tur.goto(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.colormode(255) #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内

tur.color((255,155,192),"pink")

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()

更多推荐

用python画小猪佩奇动画片全集

本文发布于:2024-03-05 00:22:41,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1710812.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:小猪   动画片   全集   python

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!