python海龟绘图(turtle)手绘【玫瑰、时钟、哆啦A梦、小猪佩奇、史迪仔】

前言

python的第三方库绘图模块turtle(因其本意有海龟、乌龟的意思,又称为海龟绘图),可以用来绘制一些很好玩的东西。之前就有盛极一时的海龟绘图绘制冰墩墩,这里给大家总结了关于海龟绘图的一些方法方便大家学习。另外提供了手绘【玫瑰、时钟、哆啦A梦、小猪佩奇、史迪仔】的源码,希望大家喜欢

安装

请先安装模块

pip install turtle

相关方法

# turtle.title  # 项目名
# turtle.speed()  # 画画速度
# turtle.penup()  # 提笔
# turtle.goto(坐标)  # 到达位置
# turtle.pencolor('color')  # 画笔颜色
# turtle.pensize()  # 画笔粗度
# turtle.begin_fill()  # 进行填充
# turtle.end_fill() #填充完毕
# turtle.pendown()  # 落笔
# turtle.setheading()  # 落笔朝向
# turtle.circle()  # 画圆
# turtle.hideturtle() #隐藏画笔的turtle形状
# turtle.showturtle() #显示画笔的turtle形状
# turtle.fillcolor(colorstring) #绘制图形的填充颜色
# turtle.color(color1, color2) #同时设置pencolor=color1, fillcolor=color2
# turtle.filling() #返回当前是否在填充状态
# turtle.done() #绘制完毕

玫瑰花

在这里插入图片描述


import turtle
turtle.speed(100)

# 设置初始位置
turtle.penup()
turtle.pensize(3)
turtle.left(90)
turtle.fd(200)
turtle.pendown()
turtle.right(90)
turtle.bgcolor('skyblue')

# 花蕊
turtle.fillcolor("red")
turtle.begin_fill()
turtle.circle(10, 180)
turtle.circle(25, 110)
turtle.left(50)
turtle.circle(60, 45)
turtle.circle(20, 170)
turtle.right(24)
turtle.fd(30)
turtle.left(10)
turtle.circle(30, 110)
turtle.fd(20)
turtle.left(40)
turtle.circle(90, 70)
turtle.circle(30, 150)
turtle.right(30)
turtle.fd(15)
turtle.circle(80, 90)
turtle.left(15)
turtle.fd(45)
turtle.right(165)
turtle.fd(20)
turtle.left(155)
turtle.circle(150, 80)
turtle.left(50)
turtle.circle(150, 90)
turtle.end_fill()

# 花瓣1
turtle.left(150)
turtle.circle(-90, 70)
turtle.left(20)
turtle.circle(75, 105)
turtle.setheading(60)
turtle.circle(80, 98)
turtle.circle(-90, 40)

# 花瓣2
turtle.left(180)
turtle.circle(90, 40)
turtle.circle(-80, 98)
turtle.setheading(-83)

# 叶子1
turtle.fd(30)
turtle.left(90)
turtle.fd(25)
turtle.left(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(-80, 90)
turtle.right(90)
turtle.circle(-80, 90)
turtle.end_fill()
turtle.right(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(85)
turtle.left(90)
turtle.fd(80)

# 叶子2
turtle.right(90)
turtle.right(45)
turtle.fillcolor("green")
turtle.begin_fill()
turtle.circle(80, 90)
turtle.left(90)
turtle.circle(80, 90)
turtle.end_fill()
turtle.left(135)
turtle.fd(60)
turtle.left(180)
turtle.fd(60)
turtle.right(90)
turtle.circle(200, 60)

# 我将玫瑰藏于身后 时刻期盼着与你赴约
turtle.pencolor('darkred')
turtle.goto(-200,-230)
turtle.write('我将玫瑰藏于身后 时刻期盼着与你赴约',font=('华文行楷',20,'bold italic'))
turtle.hideturtle()
turtle.done()

时钟(请打开最大化窗口体验)

在这里插入图片描述

# coding=utf-8
 
import turtle
from datetime import *
 
# 抬起画笔,向前运动一段距离放下
def Skip(step):
    turtle.penup()
    turtle.forward(step)
    turtle.pendown()
 
def mkHand(name, length):
    # 注册Turtle形状,建立表针Turtle
    turtle.reset()
    Skip(-length * 0.1)
    # 开始记录多边形的顶点。当前的乌龟位置是多边形的第一个顶点。
    turtle.begin_poly()
    turtle.forward(length * 1.1)
    # 停止记录多边形的顶点。当前的乌龟位置是多边形的最后一个顶点。将与第一个顶点相连。
    turtle.end_poly()
    # 返回最后记录的多边形。
    handForm = turtle.get_poly()
    turtle.register_shape(name, handForm)
 
def Init():
    global secHand, minHand, hurHand, printer
    # 重置Turtle指向北
    turtle.mode("logo")
    # 建立三个表针Turtle并初始化
    mkHand("secHand", 135)
    mkHand("minHand", 125)
    mkHand("hurHand", 90)
    secHand = turtle.Turtle()
    secHand.shape("secHand")
    minHand = turtle.Turtle()
    minHand.shape("minHand")
    hurHand = turtle.Turtle()
    hurHand.shape("hurHand")
   
    for hand in secHand, minHand, hurHand:
        hand.shapesize(1, 1, 3)
        hand.speed(0)
   
    # 建立输出文字Turtle
    printer = turtle.Turtle()
    # 隐藏画笔的turtle形状
    printer.hideturtle()
    printer.penup()
    
def SetupClock(radius):
    # 建立表的外框
    turtle.reset()
    turtle.pensize(7)
    for i in range(60):
        Skip(radius)
        if i % 5 == 0:
            turtle.forward(20)
            Skip(-radius - 20)
           
            Skip(radius + 20)
            if i == 0:
                turtle.write(int(12), align="center", font=("Courier", 14, "bold"))
            elif i == 30:
                Skip(25)
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))
                Skip(-25)
            elif (i == 25 or i == 35):
                Skip(20)
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))
                Skip(-20)
            else:
                turtle.write(int(i/5), align="center", font=("Courier", 14, "bold"))
            Skip(-radius - 20)
        else:
            turtle.dot(5)
            Skip(-radius)
        turtle.right(6)
        
def Week(t):   
    week = ["星期一", "星期二", "星期三",
            "星期四", "星期五", "星期六", "星期日"]
    return week[t.weekday()]
 
def Date(t):
    y = t.year
    m = t.month
    d = t.day
    return "%s - %d - %d" % (y, m, d)
 
def Tick():
    # 绘制表针的动态显示
    t = datetime.today()
    second = t.second + t.microsecond * 0.000001
    minute = t.minute + second / 60.0
    hour = t.hour + minute / 60.0
    secHand.setheading(6 * second)
    minHand.setheading(6 * minute)
    hurHand.setheading(30 * hour)
    
    turtle.tracer(False) 
    printer.forward(65)
    printer.write(Week(t), align="center",
                  font=("Courier", 14, "bold"))
    printer.back(130)
    printer.write(Date(t), align="center",
                  font=("Courier", 14, "bold"))
    printer.home()
    turtle.tracer(True)
 
    # 100ms后继续调用tick
    turtle.ontimer(Tick, 100)
 
def main():
    # 打开/关闭龟动画,并为更新图纸设置延迟。
    turtle.tracer(False)
    Init()
    SetupClock(160)
    turtle.tracer(True)
    Tick()
    turtle.mainloop()
 
if __name__ == "__main__":
    main()

哆啦A梦(请打开最大化窗口体验)

在这里插入图片描述

from turtle import * #画图模块


# 无轨迹跳跃
def my_goto(x, y):
    penup()
    goto(x, y)
    pendown()

# 眼睛
def eyes():
    fillcolor("#ffffff")
    begin_fill()

    tracer(False)
    a = 2.5
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:
            a -= 0.05
            lt(3)
            fd(a)
        else:
            a += 0.05
            lt(3)
            fd(a)
    tracer(True)
    end_fill()


# 胡须
def beard():
    my_goto(-32, 135)
    seth(165)
    fd(60)

    my_goto(-32, 125)
    seth(180)
    fd(60)

    my_goto(-32, 115)
    seth(193)
    fd(60)

    my_goto(37, 135)
    seth(15)
    fd(60)

    my_goto(37, 125)
    seth(0)
    fd(60)

    my_goto(37, 115)
    seth(-13)
    fd(60)

# 嘴巴
def mouth():
    my_goto(5, 148)
    seth(270)
    fd(100)
    seth(0)
    circle(120, 50)
    seth(230)
    circle(-120, 100)

# 围巾
def scarf():
    fillcolor('#e70010')
    begin_fill()
    seth(0)
    fd(200)
    circle(-5, 90)
    fd(10)
    circle(-5, 90)
    fd(207)
    circle(-5, 90)
    fd(10)
    circle(-5, 90)
    end_fill()

# 鼻子
def nose():
    my_goto(-10, 158)
    seth(315)
    fillcolor('#e70010')
    begin_fill()
    circle(20)
    end_fill()

# 黑眼睛
def black_eyes():
    seth(0)
    my_goto(-20, 195)
    fillcolor('#000000')
    begin_fill()
    circle(13)
    end_fill()

    pensize(6)
    my_goto(20, 205)
    seth(75)
    circle(-10, 150)
    pensize(3)

    my_goto(-17, 200)
    seth(0)
    fillcolor('#ffffff')
    begin_fill()
    circle(5)
    end_fill()
    my_goto(0, 0)



# 脸
def face():

    fd(183)
    lt(45)
    fillcolor('#ffffff')
    begin_fill()
    circle(120, 100)
    seth(180)
    # print(pos())
    fd(121)
    pendown()
    seth(215)
    circle(120, 100)
    end_fill()
    my_goto(63.56,218.24)
    seth(90)
    eyes()
    seth(180)
    penup()
    fd(60)
    pendown()
    seth(90)
    eyes()
    penup()
    seth(180)
    fd(64)

# 头型
def head():
    penup()
    circle(150, 40)
    pendown()
    fillcolor('#00a0de')
    begin_fill()
    circle(150, 280)
    end_fill()

# 画哆啦A梦
def Doraemon():
    # 头部
    head()

    # 围脖
    scarf()

    # 脸
    face()

    # 红鼻子
    nose()

    # 嘴巴
    mouth()

    # 胡须
    beard()

    # 身体
    my_goto(0, 0)
    seth(0)
    penup()
    circle(150, 50)
    pendown()
    seth(30)
    fd(40)
    seth(70)
    circle(-30, 270)


    fillcolor('#00a0de')
    begin_fill()

    seth(230)
    fd(80)
    seth(90)
    circle(1000, 1)
    seth(-89)
    circle(-1000, 10)

    # print(pos())

    seth(180)
    fd(70)
    seth(90)
    circle(30, 180)
    seth(180)
    fd(70)

    # print(pos())
    seth(100)
    circle(-1000, 9)

    seth(-86)
    circle(1000, 2)
    seth(230)
    fd(40)

    # print(pos())


    circle(-30, 230)
    seth(45)
    fd(81)
    seth(0)
    fd(203)
    circle(5, 90)
    fd(10)
    circle(5, 90)
    fd(7)
    seth(40)
    circle(150, 10)
    seth(30)
    fd(40)
    end_fill()

    # 左手
    seth(70)
    fillcolor('#ffffff')
    begin_fill()
    circle(-30)
    end_fill()

    # 脚
    my_goto(103.74, -182.59)
    seth(0)
    fillcolor('#ffffff')
    begin_fill()
    fd(15)
    circle(-15, 180)
    fd(90)
    circle(-15, 180)
    fd(10)
    end_fill()

    my_goto(-96.26, -182.59)
    seth(180)
    fillcolor('#ffffff')
    begin_fill()
    fd(15)
    circle(15, 180)
    fd(90)
    circle(15, 180)
    fd(10)
    end_fill()

    # 右手
    my_goto(-133.97, -91.81)
    seth(50)
    fillcolor('#ffffff')
    begin_fill()
    circle(30)
    end_fill()

    # 口袋
    my_goto(-103.42, 15.09)
    seth(0)
    fd(38)
    seth(230)
    begin_fill()
    circle(90, 260)
    end_fill()

    my_goto(5, -40)
    seth(0)
    fd(70)
    seth(-90)
    circle(-70, 180)
    seth(0)
    fd(70)

    #铃铛
    my_goto(-103.42, 15.09)
    fd(90)
    seth(70)
    fillcolor('#ffd200')
    # print(pos())
    begin_fill()
    circle(-20)
    end_fill()
    seth(170)
    fillcolor('#ffd200')
    begin_fill()
    circle(-2, 180)
    seth(10)
    circle(-100, 22)
    circle(-2, 180)
    seth(180-10)
    circle(100, 22)
    end_fill()
    goto(-13.42, 15.09)
    seth(250)
    circle(20, 110)
    seth(90)
    fd(15)
    dot(10)
    my_goto(0, -150)

    # 画眼睛
    black_eyes()

if __name__ == '__main__':
    screensize(800,600, "#f0f0f0")
    pensize(3)  # 画笔宽度
    speed(9)    # 画笔速度
    Doraemon()
    my_goto(100, -300)
    write('Hello neYan', font=("Bradley Hand ITC", 30, "bold"))
    mainloop()

小猪佩奇(请打开最大化窗口体验)

在这里插入图片描述

from turtle import*

def nose(x,y):#鼻子
    penup()#提起笔
    goto(x,y)#定位
    pendown()#落笔,开始画
    setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)
    begin_fill()#准备开始填充图形
    a=0.4
    for i in range(120):
        if 0<=i<30 or 60<=i<90:
            a=a+0.08
            left(3) #向左转3度
            forward(a) #向前走a的步长
        else:
            a=a-0.08
            left(3)
            forward(a)
    end_fill()#填充完成

    penup()
    setheading(90)
    forward(25)
    setheading(0)
    forward(10)
    pendown()
    pencolor(255,155,192)#画笔颜色
    setheading(10)
    begin_fill()
    circle(5)
    color(160,82,45)#返回或设置pencolor和fillcolor
    end_fill()

    penup()
    setheading(0)
    forward(20)
    pendown()
    pencolor(255,155,192)
    setheading(10)
    begin_fill()
    circle(5)
    color(160,82,45)
    end_fill()


def head(x,y):#头
    color((255,155,192),"pink")
    penup()
    goto(x,y)
    setheading(0)
    pendown()
    begin_fill()
    setheading(180)
    circle(300,-30)
    circle(100,-60)
    circle(80,-100)
    circle(150,-20)
    circle(60,-95)
    setheading(161)
    circle(-300,15)
    penup()
    goto(-100,100)
    pendown()
    setheading(-30)
    a=0.4
    for i in range(60):
        if 0<=i<30 or 60<=i<90:
            a=a+0.08
            lt(3) #向左转3度
            fd(a) #向前走a的步长
        else:
            a=a-0.08
            lt(3)
            fd(a)
    end_fill()


def ears(x,y): #耳朵
    color((255,155,192),"pink")
    penup()
    goto(x,y)
    pendown()
    begin_fill()
    setheading(100)
    circle(-50,50)
    circle(-10,120)
    circle(-50,54)
    end_fill()

    penup()
    setheading(90)
    forward(-12)
    setheading(0)
    forward(30)
    pendown()
    begin_fill()
    setheading(100)
    circle(-50,50)
    circle(-10,120)
    circle(-50,56)
    end_fill()


def eyes(x,y):#眼睛
    color((255,155,192),"white")
    penup()
    setheading(90)
    forward(-20)
    setheading(0)
    forward(-95)
    pendown()
    begin_fill()
    circle(15)
    end_fill()

    color("black")
    penup()
    setheading(90)
    forward(12)
    setheading(0)
    forward(-3)
    pendown()
    begin_fill()
    circle(3)
    end_fill()

    color((255,155,192),"white")
    penup()
    seth(90)
    forward(-25)
    seth(0)
    forward(40)
    pendown()
    begin_fill()
    circle(15)
    end_fill()

    color("black")
    penup()
    setheading(90)
    forward(12)
    setheading(0)
    forward(-3)
    pendown()
    begin_fill()
    circle(3)
    end_fill()


def cheek(x,y):#腮
    color((255,155,192))
    penup()
    goto(x,y)
    pendown()
    setheading(0)
    begin_fill()
    circle(30)
    end_fill()


def mouth(x,y): #嘴
    color(239,69,19)
    penup()
    goto(x,y)
    pendown()
    setheading(-80)
    circle(30,40)
    circle(40,80)

def body(x,y):#身体
    color("red",(255,99,71))
    penup()
    goto(x,y)
    pendown()
    begin_fill()
    setheading(-130)
    circle(100,10)
    circle(300,30)
    setheading(0)
    forward(230)
    setheading(90)
    circle(300,30)
    circle(100,3)
    color((255,155,192),(255,100,100))
    setheading(-135)
    circle(-80,63)
    circle(-150,24)
    end_fill()


def hands(x,y):#手
    color((255,155,192))
    penup()
    goto(x,y)
    pendown()
    setheading(-160)
    circle(300,15)
    penup()
    setheading(90)
    forward(15)
    setheading(0)
    forward(0)
    pendown()
    setheading(-10)
    circle(-20,90)

    penup()
    setheading(90)
    forward(30)
    setheading(0)
    forward(237)
    pendown()
    setheading(-20)
    circle(-300,15)
    penup()
    setheading(90)
    forward(20)
    setheading(0)
    forward(0)
    pendown()
    setheading(-170)
    circle(20,90)

def foot(x,y):#脚
    pensize(10)
    color((240,128,128))
    penup()
    goto(x,y)
    pendown()
    setheading(-90)
    forward(40)
    setheading(-180)
    color("black")
    pensize(15)
    fd(20)

    pensize(10)
    color((240,128,128))
    penup()
    setheading(90)
    forward(40)
    setheading(0)
    forward(90)
    pendown()
    setheading(-90)
    forward(40)
    setheading(-180)
    color("black")
    pensize(15)
    fd(20)

def tail(x,y):#尾巴
    pensize(4)
    color((255,155,192))
    penup()
    goto(x,y)
    pendown()
    seth(0)
    circle(70,20)
    circle(10,330)
    circle(70,30)

def setting():          #参数设置
    pensize(4)
    hideturtle()        #使乌龟无形(隐藏)
    colormode(255)      #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内
    color((255,155,192),"pink")
    setup(840,500)
    speed(10)

def main():
    setting()           #画布、画笔设置
    nose(-100,100)      #鼻子
    head(-69,167)       #头
    ears(0,160)         #耳朵
    eyes(0,140)         #眼睛
    cheek(80,10)        #腮
    mouth(-20,30)       #嘴
    body(-32,-8)        #身体
    hands(-56,-45)      #手
    foot(2,-177)        #脚
    tail(148,-155)      #尾巴
    done()

if __name__ == '__main__':
    main()

皮卡丘(请打开最大化窗口体验)

在这里插入图片描述

import turtle


def getPosition(x, y):
        turtle.setx(x)
        turtle.sety(y)
        print(x, y)

class Pikachu:

    def __init__(self):
        self.t = turtle.Turtle()
        t = self.t
        t.pensize(3)
        t.speed(9)
        t.ondrag(getPosition)

    
        
    def noTrace_goto(self, x, y):
        self.t.penup()
        self.t.goto(x, y)
        self.t.pendown()

    def leftEye(self, x, y):
        self.noTrace_goto(x, y)
        t = self.t
        t.seth(0)
        t.fillcolor('#333333')
        t.begin_fill()
        t.circle(22)
        t.end_fill()

        self.noTrace_goto(x, y+10)
        t.fillcolor('#000000')
        t.begin_fill()
        t.circle(10)
        t.end_fill()

        self.noTrace_goto(x+6, y + 22)
        t.fillcolor('#ffffff')
        t.begin_fill()
        t.circle(10)
        t.end_fill()

    def rightEye(self, x, y):
        self.noTrace_goto(x, y)
        t = self.t
        t.seth(0)
        t.fillcolor('#333333')
        t.begin_fill()
        t.circle(22)
        t.end_fill()

        self.noTrace_goto(x, y+10)
        t.fillcolor('#000000')
        t.begin_fill()
        t.circle(10)
        t.end_fill()

        self.noTrace_goto(x-6, y + 22)
        t.fillcolor('#ffffff')
        t.begin_fill()
        t.circle(10)
        t.end_fill()

    def mouth(self, x, y):
        self.noTrace_goto(x, y)
        t = self.t

        t.fillcolor('#88141D')
        t.begin_fill()
        # 下嘴唇
        l1 = []
        l2 = []
        t.seth(190)
        a = 0.7
        for i in range(28):
            a += 0.1
            t.right(3)
            t.fd(a)
            l1.append(t.position())
        
        self.noTrace_goto(x, y)
        
        t.seth(10)
        a = 0.7
        for i in range(28):
            a += 0.1
            t.left(3)
            t.fd(a)
            l2.append(t.position())
        
        # 上嘴唇
        
        t.seth(10)
        t.circle(50, 15)
        t.left(180)
        t.circle(-50, 15)
        
        t.circle(-50, 40)
        t.seth(233)
        t.circle(-50, 55)
        t.left(180)
        t.circle(50, 12.1)
        t.end_fill()

        # 舌头
        self.noTrace_goto(17, 54)
        t.fillcolor('#DD716F')
        t.begin_fill()
        t.seth(145)
        t.circle(40, 86)
        t.penup()
        for pos in reversed(l1[:20]):
            t.goto(pos[0], pos[1]+1.5)
        for pos in l2[:20]:
            t.goto(pos[0], pos[1]+1.5)
        t.pendown()
        t.end_fill()

        # 鼻子
        self.noTrace_goto(-17, 94)
        t.seth(8)
        t.fd(4)
        t.back(8)

    # 红脸颊
    def leftCheek(self, x, y):
        turtle.tracer(False)
        t = self.t
        self.noTrace_goto(x, y)
        t.seth(300)
        t.fillcolor('#DD4D28')
        t.begin_fill()
        a = 2.3
        for i in range(120):
            if 0 <= i < 30 or 60 <= i < 90:
                a -= 0.05
                t.lt(3)
                t.fd(a)
            else:
                a += 0.05
                t.lt(3)
                t.fd(a)
        t.end_fill()
        turtle.tracer(True)

    def rightCheek(self, x, y):
        t = self.t
        turtle.tracer(False)
        self.noTrace_goto(x, y)
        t.seth(60)
        t.fillcolor('#DD4D28')
        t.begin_fill()
        a = 2.3
        for i in range(120):
            if 0 <= i < 30 or 60 <= i < 90:
                a -= 0.05
                t.lt(3)
                t.fd(a)
            else:
                a += 0.05
                t.lt(3)
                t.fd(a)
        t.end_fill()
        turtle.tracer(True)

    def colorLeftEar(self, x, y):
        t = self.t
        self.noTrace_goto(x, y)
        t.fillcolor('#000000')
        t.begin_fill()
        t.seth(330)
        t.circle(100, 35)
        t.seth(219)
        t.circle(-300, 19)
        t.seth(110)
        t.circle(-30, 50)
        t.circle(-300, 10)
        t.end_fill()
        

    def colorRightEar(self, x, y):
        t = self.t
        self.noTrace_goto(x, y)
        t.fillcolor('#000000')
        t.begin_fill()
        t.seth(300)
        t.circle(-100, 30)
        t.seth(35)
        t.circle(300, 15)
        t.circle(30, 50)
        t.seth(190)
        t.circle(300, 17)
        t.end_fill()
    

    def body(self):
        t = self.t

        t.fillcolor('#F6D02F')
        t.begin_fill()
        # 右脸轮廓
        t.penup()
        t.circle(130, 40)
        t.pendown()
        t.circle(100, 105)
        t.left(180)
        t.circle(-100, 5)

        # 右耳朵
        t.seth(20)
        t.circle(300, 30)
        t.circle(30, 50)
        t.seth(190)
        t.circle(300, 36)

        # 上轮廓
        t.seth(150)
        t.circle(150, 70)
        
        # 左耳朵
        t.seth(200)
        t.circle(300, 40)
        t.circle(30, 50)
        t.seth(20)
        t.circle(300, 35)
        #print(t.pos())

        # 左脸轮廓
        t.seth(240)
        t.circle(105, 95)
        t.left(180)
        t.circle(-105, 5)

        # 左手
        t.seth(210)
        t.circle(500, 18)
        t.seth(200)
        t.fd(10)
        t.seth(280)
        t.fd(7)
        t.seth(210)
        t.fd(10)
        t.seth(300)
        t.circle(10, 80)
        t.seth(220)
        t.fd(10)
        t.seth(300)
        t.circle(10, 80)
        t.seth(240)
        t.fd(12)
        t.seth(0)
        t.fd(13)
        t.seth(240)
        t.circle(10, 70)
        t.seth(10)
        t.circle(10, 70)
        t.seth(10)
        t.circle(300, 18)

        t.seth(75)
        t.circle(500, 8)
        t.left(180)
        t.circle(-500, 15)
        t.seth(250)
        t.circle(100, 65)

        # 左脚
        t.seth(320)
        t.circle(100, 5)
        t.left(180)
        t.circle(-100, 5)
        t.seth(220)
        t.circle(200, 20)
        t.circle(20, 70)

        t.seth(60)
        t.circle(-100, 20)
        t.left(180)
        t.circle(100, 20)
        t.seth(300)
        t.circle(10, 70)

        t.seth(60)
        t.circle(-100, 20)
        t.left(180)
        t.circle(100, 20)
        t.seth(10)
        t.circle(100, 60)

        # 横向
        t.seth(180)
        t.circle(-100, 10)
        t.left(180)
        t.circle(100, 10)
        t.seth(5)
        t.circle(100, 10)
        t.circle(-100, 40)
        t.circle(100, 35)
        t.left(180)
        t.circle(-100, 10)

        # 右脚
        t.seth(290)
        t.circle(100, 55)
        t.circle(10, 50)

        t.seth(120)
        t.circle(100, 20)
        t.left(180)
        t.circle(-100, 20)

        t.seth(0)
        t.circle(10, 50)

        t.seth(110)
        t.circle(100, 20)
        t.left(180)
        t.circle(-100, 20)

        t.seth(30)
        t.circle(20, 50)

        t.seth(100)
        t.circle(100, 40)

        # 右侧身体轮廓
        t.seth(200)
        t.circle(-100, 5)
        t.left(180)
        t.circle(100, 5)
        t.left(30)
        t.circle(100, 75)
        t.right(15)
        t.circle(-300, 21)
        t.left(180)
        t.circle(300, 3)

        # 右手
        t.seth(43)
        t.circle(200, 60)
        

        t.right(10)
        t.fd(10)

        t.circle(5, 160)
        t.seth(90)
        t.circle(5, 160)
        t.seth(90)

        
        t.fd(10)
        t.seth(90)
        t.circle(5, 180)
        t.fd(10)

        t.left(180)
        t.left(20)
        t.fd(10)
        t.circle(5, 170)
        t.fd(10)
        t.seth(240)
        t.circle(50, 30)

        
        t.end_fill()
        self.noTrace_goto(130, 125)
        t.seth(-20)
        t.fd(5)
        t.circle(-5, 160)
        t.fd(5)

        # 手指纹
        self.noTrace_goto(166, 130)
        t.seth(-90)
        t.fd(3)
        t.circle(-4, 180)
        t.fd(3)
        t.seth(-90)
        t.fd(3)
        t.circle(-4, 180)
        t.fd(3)

        # 尾巴
        self.noTrace_goto(168, 134)
        t.fillcolor('#F6D02F')
        t.begin_fill()
        t.seth(40)
        t.fd(200)
        t.seth(-80)
        t.fd(150)
        t.seth(210)
        t.fd(150)
        t.left(90)
        t.fd(100)
        t.right(95)
        t.fd(100)
        t.left(110)
        t.fd(70)
        t.right(110)
        t.fd(80)
        t.left(110)
        t.fd(30)
        t.right(110)
        t.fd(32)

        t.right(106)
        t.circle(100, 25)
        t.right(15)
        t.circle(-300, 2)
        ##############
        #print(t.pos())
        t.seth(30)
        t.fd(40)
        t.left(100)
        t.fd(70)
        t.right(100)
        t.fd(80)
        t.left(100)
        t.fd(46)
        t.seth(66)
        t.circle(200, 38)
        t.right(10)
        t.fd(10)
        t.end_fill()



        # 尾巴花纹 
        t.fillcolor('#923E24')
        self.noTrace_goto(126.82, -156.84)
        t.begin_fill()
        
        t.seth(30)
        t.fd(40)
        t.left(100)
        t.fd(40)
        t.pencolor('#923e24')
        t.seth(-30)
        t.fd(30)
        t.left(140)
        t.fd(20)
        t.right(150)
        t.fd(20)
        t.left(150)
        t.fd(20)
        t.right(150)
        t.fd(20)
        t.left(130)
        t.fd(18)
        t.pencolor('#000000')
        t.seth(-45)
        t.fd(67)
        t.right(110)
        t.fd(80)
        t.left(110)
        t.fd(30)
        t.right(110)
        t.fd(32)
        t.right(106)
        t.circle(100, 25)
        t.right(15)
        t.circle(-300, 2)
        t.end_fill()
        

        # 帽子、眼睛、嘴巴、脸颊
        self.cap(-134.07, 147.81)
        self.mouth(-5, 25)
        self.leftCheek(-126, 32)
        self.rightCheek(107, 63)
        self.colorLeftEar(-250, 100)
        self.colorRightEar(140, 270)
        self.leftEye(-85, 90)
        self.rightEye(50, 110)
        t.hideturtle()
        


    def cap(self, x, y):
        self.noTrace_goto(x, y)
        t = self.t
        t.fillcolor('#CD0000')
        t.begin_fill()
        t.seth(200)
        t.circle(400, 7)
        t.left(180)
        t.circle(-400, 30)
        t.circle(30, 60)
        t.fd(50)
        t.circle(30, 45)
        t.fd(60)
        t.left(5)
        t.circle(30, 70)
        t.right(20)
        t.circle(200, 70)
        t.circle(30, 60)
        t.fd(70)
        # print(t.pos())
        t.right(35)
        t.fd(50)
        t.circle(8, 100)
        t.end_fill()
        self.noTrace_goto(-168.47, 185.52)
        t.seth(36)
        t.circle(-270, 54)
        t.left(180)
        t.circle(270, 27)
        t.circle(-80, 98)

        t.fillcolor('#444444')
        t.begin_fill()
        t.left(180)
        t.circle(80, 197)
        t.left(58)
        t.circle(200, 45)
        t.end_fill()

        self.noTrace_goto(-58, 270)
        t.pencolor('#228B22')
        t.dot(35)

        self.noTrace_goto(-30, 280)
        t.fillcolor('#228B22')
        t.begin_fill()
        t.seth(100)
        t.circle(30, 180)
        t.seth(190)
        t.fd(15)
        t.seth(100)
        t.circle(-45, 180)
        t.right(90)
        t.fd(15)
        t.end_fill()
        t.pencolor('#000000')




    def start(self):
        self.body()



def main():
    print('Painting the Pikachu... ')
    turtle.screensize(800, 600)
    turtle.title('Pikachu')
    pikachu = Pikachu()
    pikachu.start()
    turtle.mainloop()
    

if __name__ == '__main__':
    main()

史迪仔(请打开最大化窗口体验)

在这里插入图片描述

from turtle import *
setup(650,650)
penup()
pensize(5)
speed(1000)
pencolor("#065693")
seth(180)
fd(140)
seth(-90)
fd(50)
pendown()      #起点
fillcolor("#0079C6")
begin_fill()
seth(170)
circle(-40,100)
seth(180)
fd(50)
seth(180)
circle(-10,46)
seth(130)
circle(-300,40)#耳朵外廓大圆
circle(-100,45)
right(10)
circle(-50,30)
right(10)
circle(-30,30)
left(1)
fd(2)
right(1)
fd(3)
right(4)
fd(3)
right(3)
fd(5)
right(4)
fd(6)
right(4)
fd(10)
right(4)
fd(10)
right(3)
fd(15)
right(2)
fd(20)
right(2)
fd(20)
right(4)
fd(20)
right(3)
fd(30)
right(1)
fd(40)
right(1)
fd(60)
seth(-115)
fd(5)    #脸左侧开始逆时针
circle(200,30)
end_fill()
begin_fill()
left(8)
fd(20)
left(10)
fd(20)
left(14)
circle(100,30)
left(10)
circle(150,20)
right(2)
fd(55)
left(5)
fd(40)
left(3)
fd(25)
right(3)
circle(150,20)
left(7)
circle(100,30)
fd(5)#右侧耳朵下部开始
left(3)
circle(80,30)
right(3)
circle(80,30)
right(9)
circle(100,30)
left(2)
circle(200,20)
left(3)
fd(20)
seth(108)#小毛尖儿1
circle(30,5)
right(3)
circle(200,3)
left(7)
circle(20,5)
circle(15,10)
left(5)
circle(15,20)
left(11)
circle(15,20)
left(10)
circle(15,20)
left(9)
circle(13,15)
left(10)
circle(13,15)
left(8)
circle(20,15)
seth(135)  #小毛尖2
fd(20)
circle(8,168)
right(180)  #小毛尖3
circle(7,170)
seth(-176) #顶部结尾
fd(3)
circle(100,10)
right(5)
circle(70,15)
fd(3)
right(5)
circle(100,10)
right(4)
circle(80,10)
left(5)
circle(100,5)
right(6)
circle(100,5)
left(1)
circle(50,10)
right(10)
fd(9)
seth(-115)
fd(5)
circle(200,30)
end_fill() #脸廓结束
penup()    #眼睛左开始
seth(0)
fd(15)
seth(-60)
pendown()
fillcolor("#69C4EF")
begin_fill()
circle(50,20)
left(4)
circle(55,20)
right(4)
circle(50,20)
right(4)
circle(50,20)
left(13)
circle(50,20)
left(15)
circle(50,30)
right(10)
circle(80,20)
right(10)
circle(80,20)
right(7)
circle(80,20)
left(10)
circle(80,15)
left(17)
circle(80,15)
left(30)
circle(80,15)
left(10)
circle(80,15)
circle(80,15)
right(8)
circle(80,15)
right(7)
circle(80,15)
right(7)
circle(80,6)
end_fill()
penup()   #左眼内部(黑)开始
seth(0)
fd(34)
seth(90)
fd(10)
seth(-60)
pendown()
fillcolor("black")
begin_fill()
pencolor("black")
pensize(1)
circle(80,7)
left(20)
circle(80,9)
left(25)
circle(80,9)
left(30)
circle(80,9)
left(35)
circle(80,9)
left(10)
circle(80,3)
right(15)
fd(13)
left(15)
circle(80,10)
left(20)
circle(80,15)
left(25)
circle(80,10)
left(30)
circle(80,9)
left(35)
circle(80,15)
left(10)
circle(80,9)
circle(80,15)
end_fill() #左眼内部(黑)结束
penup()  #左眼内部(白)开始
seth(90)
fd(47)
seth(0)
fd(12)
pendown()
fillcolor("white")
begin_fill()
circle(-10,360)
end_fill() #左眼整体结束
penup()    #右眼开始
seth(0)
fd(237)
seth(-90)
pensize(5)
pencolor("#065693")
fillcolor("#69C4EF")
begin_fill()
pendown()
right(10)
circle(80,11)
right(30)
circle(80,11)
right(35)
circle(80,15)
right(35)
circle(80,12)
right(20)
circle(80,9)
right(37)
circle(80,9)
right(40)
circle(80,9)
right(38)
circle(80,9)
right(15)
circle(80,9)
fd(7)
right(11)
circle(80,9)
right(11)
circle(80,9)
right(12)
circle(80,9)
right(14)
circle(80,9)
right(16)
circle(80,5)
right(16)
circle(80,5)
right(18)
circle(80,5)
right(23)
circle(80,5)
right(25)
circle(80,5)
right(28)
circle(80,5)
right(5)
circle(80,5)
right(12)
circle(80,5)
right(15)
circle(80,5)
right(17)
circle(80,5)
right(15)
circle(80,5)
right(13)
circle(80,5)
right(13)
circle(80,9)
right(11)
circle(80,9)
right(11)
circle(80,5)
right(10)
circle(80,5)
right(10)
circle(80,9)
end_fill() #右眼外框结束
penup()    #右眼内部开始
seth(180)
fd(70)
seth(87)
pensize(1)
pencolor("black")
fillcolor("black")
begin_fill()
pendown()
circle(80,8)
right(15)
circle(80,7)
right(18)
circle(80,5)
right(23)
circle(80,5)
right(23)
circle(80,5)
right(23)
circle(80,5)
right(28)
circle(80,5)
right(35)
circle(80,5)
right(35)
circle(80,6)
right(37)
circle(80,6)
fd(5)
left(5)
circle(80,5)
right(3)
fd(5)
right(10)
circle(80,5)
right(15)
circle(80,5)
right(18)
circle(80,5)
right(25)
circle(80,5)
right(37)
circle(80,5)
right(38)
circle(80,7)
right(42)
circle(80,9)
right(38)
circle(80,9)
right(40)
fd(5)
end_fill()
penup() #右眼内部(白)开始
seth(0)
fd(22)
seth(90)
fd(10)
pendown()
pensize(1)
pencolor("white")
fillcolor("white")
begin_fill()
circle(10,360)
end_fill()#右眼内部(白)结束
penup()   #鼻子外开始
seth(180)
fd(167)
seth(-90)
fd(60)
pencolor("#07548C")
seth(0)
pendown()
fillcolor("#07548C")
begin_fill()
left(83)
circle(-80,30)
right(15)
circle(-80,30)
fd(5)
left(2)
circle(-80,15)
circle(-80,10)
circle(-80,20)
left(2)
circle(-80,9)
right(20)
circle(-80,20)
right(25)
circle(-80,20)
right(10)
circle(-80,15)
right(8)
circle(-80,12)
seth(-175)
fd(9)
left(2)
fd(6)
left(2)
fd(8)
right(3)
circle(-80,10)
right(3)
circle(-80,12)
circle(-80,10)
right(3)
circle(-80,10)
right(7)
circle(-80,10)
right(6)
circle(-80,8)
right(6)
circle(-80,8)
right(7)
circle(-80,7)
end_fill()#鼻子外结束
penup()#鼻子内开始
seth(8)
fd(20)
seth(-90)
fd(45)
pensize(1)
pencolor("#0A3873")
pendown()
fillcolor("#0A3873")
begin_fill()
seth(-30)
fd(20)
seth(110)
fd(20)
left(70)
circle(10,100)
end_fill()
penup()
seth(3)
fd(87)
seth(-90)
fd(5)
seth(47)
begin_fill()
pendown()
fd(20)
seth(227)
fd(20)
right(150)
fd(20)
right(70)
circle(-10,100)
end_fill()#鼻子结束
penup()#右耳朵开始
seth(0)
fd(95)
seth(90)
fd(45)
pendown()
fillcolor("#0079C6")
begin_fill()
pensize(5)
pencolor("#065693")
seth(20)
circle(40,95)
right(100)
fd(50)
circle(10,46)
seth(45)
circle(300,40)
circle(100,45)
left(10)
circle(50,30)
left(10)
circle(30,30)
right(1)
fd(2)
left(1)
fd(3)
left(4)
fd(3)
left(3)
fd(5)
left(4)
fd(6)
left(4)
fd(10)
left(4)
fd(10)
left(3)
fd(15)
left(2)
fd(20)
left(2)
fd(20)
left(4)
fd(20)
left(3)
fd(30)
left(1)
fd(40)
left(1)
fd(60)
left(3)
fd(51)
left(70)
pensize(1)
fd(8)
right(3)
fd(8)
right(3)
fd(8)
right(3)
fd(5)
right(3)
fd(5)
right(2)
fd(5)
right(2)
fd(5)
right(3)
fd(9)
right(3)
fd(10)
right(3)
fd(9)
right(5)
fd(9)
right(6)
fd(6)
right(6)
fd(6)
right(7)
fd(6)
right(7)
fd(6)
end_fill()#右耳朵外廓完成
penup()#右耳内廓开始
seth(0)
fd(6)
seth(90)
fd(20)
seth(45)
pendown()
pensize(1)
pencolor("#F7CEDC")
fillcolor("#F7CEDC")
begin_fill()
circle(40,75)
right(106)
fd(53)
circle(10,40)
seth(47)
circle(310,40)
left(10)
circle(80,45)
left(25)
circle(40,30)
left(23)
circle(30,20)
seth(-145)
right(1)
fd(2)
left(1)
fd(3)
left(4)
fd(3)
left(3)
fd(5)
left(4)
fd(6)
left(4)
fd(10)
left(4)
fd(10)
left(3)
fd(15)
left(2)
fd(20)
left(2)
fd(20)
left(3)
fd(20)
left(2)
fd(30)
left(2)
fd(30)
left(2)
fd(40)
left(3)
fd(30)
left(1)
fd(7)
left(2)
fd(7)
left(12)
fd(2)
left(8)
fd(20)
left(10)
fd(10)
left(15)
fd(10)
right(2)
fd(20)
right(10)
fd(15)
right(8)
fd(10)
end_fill()#右耳内廓结束
penup()
seth(180)
fd(327)
seth(-90)
fd(34)
pendown()
begin_fill()
seth(140)
circle(-40,75)
left(113)
fd(53)
circle(-7,40)
seth(130)
circle(-310,40)
right(17)
circle(-80,45)
right(20)
circle(-40,30)
right(23)
circle(30,20)
seth(-47)
left(3)
fd(2)
right(2)
fd(3)
right(2)
fd(3)
right(3)
fd(5)
right(4)
fd(6)
right(4)
fd(10)
right(4)
fd(10)
right(3)
fd(15)
right(1)
fd(20)
right(1)
fd(20)
right(1)
fd(30)
right(1)
fd(40)
right(1)
fd(40)
right(11)
fd(2)
right(15)
left(20)
right(10)
fd(20)
right(15)
fd(10)
left(5)
fd(20)
right(5)
fd(20)
left(10)
fd(20)
left(3)
fd(20)
end_fill()#脸部结束
penup()#身体开始
seth(0)
fd(70)
seth(-90)
fd(80)
pensize(5)
pencolor("#065693")
fillcolor("#0079C6")
begin_fill()
seth(-112)
pendown()
circle(220,22)
right(86)
circle(70,40)
right(90)
fd(8)
right(33)
circle(10,160)
right(9)
fd(8)
right(50)
fd(9)
right(28)
fd(6)
circle(8,160)
left(5)
fd(6)
right(85)
fd(9)
right(28)
fd(6)
circle(6,110)
fd(4)
right(23)
fd(5)
left(2)
circle(80,10)
left(2)
circle(80,5)
left(4)
circle(80,10)
left(7)
circle(80,10)
left(7)
circle(80,10)
right(2)
fd(5)
right(1)
circle(80,10)
left(4)
circle(80,10)
right(10)
circle(-80,10)
right(8)
circle(-80,10)
right(11)
circle(-80,10)
right(90)
fd(5)
right(5)
circle(10,180)
fd(2)
right(130)
fd(5)
left(5)
circle(10,130)
fd(5)
right(80)
fd(5)
circle(10,180)
seth(0)
fd(65)
right(180)
circle(10,190)
fd(5)
right(90)
fd(5)
circle(10,150)
left(10)
fd(5)
right(90)
fd(2)
circle(10,180)
right(20)
fd(3)
right(125)
circle(-80,10)
right(11)
circle(-80,10)
right(8)
circle(-80,10)
right(10)
circle(80,10)
left(4)
circle(80,10)
right(1)
fd(5)
right(2)
circle(80,10)
left(7)
circle(80,10)
left(7)
circle(80,10)
left(4)
circle(80,5)
left(2)
circle(80,10)
left(2)
fd(5)
right(23)
fd(4)
circle(6,110)
fd(6)
right(28)
fd(9)
right(85)
fd(6)
left(5)
circle(8,160)
fd(6)
right(28)
fd(9)
right(50)
fd(8)
right(9)
circle(10,160)
right(33)
fd(8)
right(90)
circle(70,40)
right(92)
circle(210,22)
fd(16)#身体外廓结束
left(90)
circle(-80,5)
right(1)
circle(-80,5)
right(1)
circle(80,5)
right(1)
circle(80,5)
right(2)
fd(5)
right(1)
fd(5)
right(1)
fd(5)
right(3)
fd(5)
right(2)
fd(5)
right(3)
fd(7)
right(2)
fd(7)
right(2)
fd(7)
left(2)
fd(5)
left(2)
fd(7)
right(3)
fd(7)
left(2)
fd(7)
right(2)
fd(7)
left(2)
fd(7)
right(2)
fd(7)
left(2)
fd(7)
right(2)
fd(7)
left(2)
fd(7)
right(2)
fd(7)
left(2)
fd(7)
right(5)
fd(7)
left(2)
fd(7)
right(7)
fd(7)
left(2)
fd(7)
right(8)
fd(6)
end_fill()#身体外廓结束
penup()#身体内部开始
seth(0)
fd(48)
right(65)
pendown()
fillcolor("#69C4EF")
begin_fill()
circle(-300,24)
circle(10,90)
seth(0)
fd(50)
circle(10,90)
left(9)
circle(-300,26)
fd(3)
seth(-167)
fd(5)
right(1)
fd(7)
left(1)
fd(7)
right(2)
fd(7)
left(1)
fd(7)
right(3)
fd(7)
left(2)
fd(7)
right(3)
fd(7)
right(3)
fd(7)
left(2)
fd(7)
right(4)
fd(7)
left(2)
fd(7)
right(3)
fd(7)
left(2)
fd(7)
right(2)
fd(7)
left(3)
fd(7)
left(3)
fd(5)
end_fill()#身体外廓中间结束
penup()
seth(-90)
fd(154)
seth(0)
fd(4)
pensize(1)
fillcolor("#065693")
pencolor("#065693")
pendown()
begin_fill()
seth(-155)
fd(8)
right(120)
fd(8)
right(90)
circle(-10,50)
end_fill()
penup()
seth(0)
fd(16)
seth(-120)
pendown()
fd(8)
begin_fill()
right(113)
fd(8)
right(90)
circle(-10,57)
end_fill()
penup()
seth(0)
fd(10)
seth(90)
fd(10)
pendown()
begin_fill()
seth(-45)
fd(8)
right(120)
fd(8)
right(90)
circle(-10,57)
end_fill()
penup()
seth(0)
fd(72)
seth(-90)
fd(2)
seth(-115)
pendown()#
begin_fill()
fd(8)
left(90)
circle(10,57)
end_fill()
penup()
seth(0)
fd(4)
seth(-90)
fd(6)
seth(-70)
pendown()
begin_fill()
fd(8)
left(90)
circle(10,57)
end_fill()
penup()
seth(0)
fd(4)
seth(90)
fd(5)
seth(0)
pendown()
begin_fill()
fd(8)
left(90)
circle(10,57)
end_fill()#手结束
penup()#左脚掌开始
seth(180)
fd(237)
seth(-90)
fd(10)
seth(180)
pendown()
fillcolor("#065693")
begin_fill()
circle(-17,360)
end_fill()#左脚掌结束
seth(180)#左脚丫开始
penup()
fd(20)
seth(90)
fd(7)
seth(180)
right(15)
pendown()
begin_fill()
fd(9)
right(120)
fd(9)
right(120)
fd(9)
end_fill()
penup()
seth(90)
fd(20)
seth(180)
right(53)
pendown()
begin_fill()
fd(9)
right(120)
fd(9)
right(120)
fd(9)
end_fill()
penup()
seth(0)
fd(10)
seth(90)
fd(10)
right(20)
pendown()
begin_fill()
fd(9)
right(120)
fd(9)
right(120)
fd(9)
end_fill()#左脚丫结束
penup()#右脚掌开始
seth(0)
fd(345)
seth(-90)
fd(12)
seth(0)
pendown()
begin_fill()
circle(17,360)
end_fill()#右脚掌结束
penup()#右脚丫开始
fd(23)
seth(90)
fd(4)
seth(0)
left(90)
pendown()
begin_fill()
fd(9)
right(120)
fd(9)
right(120)
fd(9)
end_fill()
penup()
seth(90)
fd(25)
seth(0)
left(127)
pendown()
begin_fill()
fd(9)
right(120)
fd(9)
right(120)
fd(9)
end_fill()
penup()
seth(180)
fd(27)
seth(90)
fd(12)
seth(0)
pendown()
begin_fill()
left(4)
fd(9)
left(120)
fd(9)
left(120)
fd(9)
end_fill()
penup()#右脚丫结束
fd(200)
done()

猜你喜欢

转载自blog.csdn.net/weixin_51033461/article/details/125781617