使用Python turtle画小猪佩奇

使用Python库简单的画一个小猪佩奇
画出来的效果如图:在这里插入图片描述

代码如下

import turtle as t
t.colormode(255)
t.speed(0)

#设置背景
t.penup()
t.goto(-300,300)
t.pendown()
t.color(73,209,249)
t.pensize(800)
t.forward(800)

t.penup()
t.goto(-300,-250)
t.pendown()
t.color(44,195,32)
t.pensize(400)
t.forward(900)

#画白云
t.penup()
t.goto(-175,220)
t.pendown()
t.pensize(1)
def filled_circle(radius, color):
    t.color(color)
    t.begin_fill()
    t.circle(radius)
    t.end_fill()

radius = 25
cloud_color="white"

filled_circle(radius,cloud_color)
t.forward(radius)
for i in range(4):
    filled_circle(radius,cloud_color)
    t.right(90)

t.penup()
t.goto(185,150)
t.pendown()


radius = 35
cloud_color="white"

filled_circle(radius,cloud_color)
t.forward(radius)
for i in range(4):
    filled_circle(radius,cloud_color)
    t.right(90)



#画鼻子
t.speed(0)
t.penup()
t.goto(-100,80)
t.pendown()
t.speed(1)
t.color(255,192,203)
t.begin_fill()
t.pencolor(240,128,128)
t.pensize(3)
t.seth(-30)
t.begin_fill()
a = 0.3
for i in range(120):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.05
        t.left(3)  # 向左转3度
        t.forward(a)  # 向前走a的步长
    else:
        a = a - 0.05
        t.left(3)
        t.forward(a)
t.end_fill()
t.penup()
t.seth(70)
t.forward(25)
t.pendown()
t.color(178,34,34)
t.begin_fill()
t.circle(3)
t.end_fill()
t.penup()
t.seth(-50)
t.forward(9)
t.pendown()
t.begin_fill()
t.circle(3)
t.end_fill()

#画头
t.speed(0)
t.color(255,192,203)
t.pencolor(240,128,128)
t.penup()
t.seth(60)
t.forward(27)
t.pendown()
t.begin_fill()
t.seth(180)
t.circle(270,-25)
t.circle(60,-125)
t.circle(100,-20)
t.circle(45,-135)
t.right(90)
t.circle(270,16)
t.seth(-30)
a = 0.3
t.pensize(0)
for i in range(60):
    if 0 <= i < 30 or 60 <= i < 90:
        a = a + 0.05
        t.left(3)  # 向左转3度
        t.forward(a)  # 向前走a的步长
    else:
        a = a - 0.05
        t.left(3)
        t.forward(a)

t.end_fill()

#画耳朵
t.speed(0)
t.pensize(3)
t.color(255,192,203)
t.penup()
t.seth(90)
t.forward(-13)
t.seth(0)
t.forward(80)
t.pendown()
t.pencolor(240,128,128)
t.begin_fill()
t.seth(100)
t.circle(-40,50)
t.circle(-10,120)
t.circle(-40,57)
t.end_fill()
t.penup()
t.seth(90)
t.forward(-6)
t.seth(0)
t.forward(12)
t.pendown()
t.begin_fill()
t.seth(100)
t.circle(-40,50)
t.circle(-10,120)
t.circle(-40,59)
t.end_fill()

#画眼睛
t.speed(0)
t.penup()
t.goto(-40,100)
t.pendown()
t.pensize(3)
t.color(255,255,255)
t.pencolor(240,128,128)
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.seth(90)
t.forward(-10)
t.seth(0)
t.forward(10)
t.pendown()
t.pencolor(0,0,0)
t.circle(2)
t.penup()
t.goto(0,75)
t.pendown()
t.pensize(3)
t.color(255,255,255)
t.pencolor(240,128,128)
t.begin_fill()
t.circle(10)
t.end_fill()
t.penup()
t.seth(90)
t.forward(5)
t.seth(0)
t.forward(2)
t.pendown()
t.pencolor(0,0,0)
t.circle(2)

#画嘴
t.penup()
t.goto(-20,30)
t.pendown()
t.pensize(4)
t.pencolor(225,81,144)
t.seth(0)
t.right(50)
t.circle(25,100)

#画腮红
t.penup()
t.goto(60,50)
t.pendown()
t.color(255,106,106)
t.begin_fill()
t.circle(12)
t.end_fill()

#画身体
t.speed(1)
t.penup()
t.seth(90)
t.forward(-65)
t.seth(180)
t.forward(80)
t.pendown()
t.color(236,94,82)
t.pencolor(233,30,15)
t.begin_fill()
t.seth(-130)
t.circle(80,10)
t.circle(250,25)
t.seth(0)
t.forward(180)
t.seth(90)
t.circle(250,25)
t.circle(80,30)
t.seth(60)
t.pencolor(240,128,128)
t.pensize(1)
t.circle(60,-45)
t.circle(100,-15)
t.circle(45,-30)
t.end_fill()

#画手
t.penup()
t.seth(90)
t.forward(-35)
t.seth(180)
t.forward(28)
t.pendown()
t.seth(135)
t.pencolor(255,192,203)
t.pensize(8)
t.forward(55)
t.penup()
t.backward(15)
t.seth(90)
t.pendown()
t.forward(20)
t.penup()
t.backward(20)
t.seth(180)
t.pendown()
t.forward(12)
t.penup()
t.seth(0)
t.forward(190)
t.seth(270)
t.forward(27)
t.seth(45)
t.pendown()
t.pencolor(255,192,203)
t.pensize(8)
t.forward(55)
t.penup()
t.backward(15)
t.seth(90)
t.pendown()
t.forward(20)
t.penup()
t.backward(20)
t.seth(0)
t.pendown()
t.forward(14)

#画尾巴
t.penup()
t.seth(90)
t.forward(-80)
t.seth(180)
t.forward(30)
t.seth(0)
t.pendown()
t.pencolor(255,192,203)
t.pensize(6)
t.circle(70,20)
t.circle(10,330)
t.circle(70,30)

#画左脚
t.speed(0)
t.penup()
t.seth(90)
t.forward(-37)
t.seth(0)
t.forward(-180)
t.pendown()
t.seth(270)
t.pendown()
t.pensize(8)
t.pencolor(255,192,203)
t.forward(15)
t.color(249,241,98)
t.pencolor(236,222,71)
t.pensize(3)
t.seth(180)
t.begin_fill()
t.forward(10)
t.seth(270)
t.forward(13)
t.seth(180)
t.forward(18)
t.circle(10,180)
t.forward(40)
t.seth(90)
t.forward(32)
t.seth(180)
t.forward(12)
t.end_fill()

#画右脚
t.penup()
t.seth(90)
t.forward(15)
t.seth(0)
t.forward(90)
t.seth(270)
t.pendown()
t.pensize(8)
t.pencolor(255,192,203)
t.forward(15)
t.color(249,241,98)
t.pencolor(236,222,71)
t.pensize(3)
t.seth(180)
t.begin_fill()
t.forward(10)
t.seth(270)
t.forward(13)
t.seth(180)
t.forward(18)
t.circle(10,180)
t.forward(40)
t.seth(90)
t.forward(32)
t.seth(180)
t.forward(12)
t.end_fill()
t.hideturtle()
t.done()

猜你喜欢

转载自blog.csdn.net/m0_57206390/article/details/126994981