turtle库绘制老虎

  网上对于turtle库的介绍很多,主要是自己理解其用法,turtle库可以说很适合python初学者学习吧,难度不大,仔细学习该库的用法便可绘制自己想要绘制的任何图像了。想要代码的通过链接下载即可:https://download.csdn.net/download/qq_45087676/86833262
  结果图如下所示。
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

#!/user/bin/env python3
# -*- coding: utf-8 -*-
import turtle as t

def tiger():
    t.screensize(100, 300)
    t.title('小老虎')
    t.shape("classic")
    t.pensize(5)# 画笔粗细
    t.color('orange')
    t.fillcolor("orange")# 填充的颜色
    t.speed(10)
    t.hideturtle()

    t.penup()  # 起笔
    t.goto(-105, 215)  # 定位开始的坐标
    t.fillcolor("orange")  # 填充的颜色
    t.begin_fill()
    t.pendown()
    t.pensize(1)
    t.setheading(220)
    t.forward(120)
    t.setheading(-58)
    t.forward(290)  #
    t.setheading(0)
    t.forward(140)
    t.setheading(73.5)
    t.forward(286)
    t.setheading(156.5)
    t.forward(92)
    t.end_fill()

    # 左耳
    t.penup()#起笔
    t.color("black")# 画笔颜色
    t.pensize(5)  # 画笔粗细
    t.goto(-100, 200)# 定位开始的坐标
    t.pendown()
    t.fillcolor("orange")# 填充的颜色
    t.begin_fill()
    t.setheading(110)# 设置朝向
    t.circle(60, 90)
    t.left(5)
    t.forward(0.5)  # 前进的距离
    t.circle(65, 25)  # 前面的参数控制前进的长度,后面的参数控制弧度
    t.left(5)
    t.forward(0.5)  # 前进的距离
    t.circle(60, 90)
    t.end_fill()

    t.penup()#起笔
    t.goto(-120, 180)# 定位开始的坐标
    t.fillcolor("orange")# 填充的颜色
    t.begin_fill()
    t.pendown()
    t.setheading(110)# 设置朝向
    t.circle(30, 90)
    t.left(5)
    t.forward(0.5)  # 前进的距离
    t.circle(35, 25)  # 前面的参数控制前进的长度,后面的参数控制弧度
    t.left(5)
    t.forward(0.5)  # 前进的距离
    t.circle(30, 90)
    t.right(-70)
    t.forward(55)
    t.end_fill()

    #左头围
    t.penup()  # 起笔
    t.goto(-200, 150)  # 定位开始的坐标
    t.fillcolor("orange")# 填充的颜色
    t.begin_fill()
    t.pendown()
    t.setheading(-120)  # 设置朝向
    t.circle(90, 30)

    t.left(5)
    t.forward(1)  # 前进的距离
    t.circle(-80, 60)

    t.right(-100)
    t.circle(150, 20)

    t.left(210)
    t.forward(1)  # 前进的距离
    t.circle(90, 20)

    t.right(-120)
    t.circle(120, 20)

    t.left(200)
    t.circle(120, 10)

    t.right(-125)
    t.circle(380, 30)
    t.end_fill()

  #### 头顶
    t.penup()  # 起笔
    t.goto(-105, 215)  # 定位开始的坐标
    t.fillcolor("orange")# 填充的颜色
    t.begin_fill()
    t.pendown()
    t.pensize(8)  # 画笔粗细
    t.setheading(10)  # 设置朝向
    t.left(3)
    t.circle(-400, 15)
    t.right(3)
    t.circle(-400, 15)
    t.end_fill()


###右耳
    t.penup()  # 起笔
    t.goto(80, 210)  # 定位开始的坐标
    t.fillcolor("orange")# 填充的颜色
    t.begin_fill()
    t.pendown()
    t.pensize(8)  # 画笔粗细
    t.setheading(60)  # 设置朝向
    t.right(10)
    t.circle(-110, 20)
    t.right(10)
    t.circle(-90, 20)
    t.right(10)
    t.circle(-80, 20)
    t.right(10)
    t.circle(-60, 20)
    t.right(10)
    t.circle(-60, 20)
    t.right(10)
    t.circle(-80, 20)
    t.end_fill()

    t.penup()  # 起笔
    t.goto(100, 200)  # 定位开始的坐标
    t.fillcolor("orange")# 填充的颜色
    t.begin_fill()
    t.pendown()
    t.pensize(5)  # 画笔粗细
    t.setheading(60)  # 设置朝向
    t.right(12)
    t.circle(-80, 20)
    t.right(12)
    t.circle(-40, 20)
    t.right(12)
    t.circle(-40, 20)
    t.right(12)
    t.circle(-30, 20)
    t.right(12)
    t.circle(-30, 20)
    t.right(12)
    t.circle(-40, 20)
    t.right(70)
    t.forward(55)
    t.end_fill()

    # 右头围
    t.penup()  # 起笔
    t.goto(176, 163)  # 定位开始的坐标
    t.fillcolor("orange")# 填充的颜色
    t.begin_fill()
    t.pendown()
    t.setheading(300)  # 设置朝向
    t.circle(-50, 10)#-10 为顺时针 10 为逆时针画
    t.right(5)
    t.circle(290, 20)

    t.right(10)
    t.circle(20, 60)

    t.right(120)
    t.circle(-40, 20)

    t.right(230)
    t.circle(50, 20)

    t.left(-130)
    t.circle(-85, 20)

    t.right(210)
    t.circle(150, 10)

    t.right(140)
    t.circle(-400, 30)
    t.end_fill()

    #王字1
    t.penup()  # 起笔
    t.color("black")  # 画笔颜色
    t.goto(-50, 225)  # 定位开始的坐标
    t.fillcolor("black")  # 填充的颜色
    t.pendown()
    t.begin_fill()
    t.pensize(2)  # 画笔粗细
    t.setheading(310)  # 设置朝向
    t.circle(-300, 30)
    t.right(60)
    t.setheading(70)  # 设置朝向
    t.circle(270, 30)
    t.end_fill()

    t.penup()  # 起笔
    t.goto(-100, 170)  # 定位开始的坐标
    t.fillcolor("black")  # 填充的颜色
    t.pendown()
    t.begin_fill()
    t.pensize(2)  # 画笔粗细
    t.setheading(50)  # 设置朝向
    t.circle(-100, 60)
    t.left(5)
    t.circle(-290, 20)
    t.left(5)
    t.circle(-40, 20)
    t.right(150)
    t.circle(585, 20)
    t.end_fill()

    # # 王字2
    t.penup()  # 起笔
    t.goto(-80, 140)  #
    t.fillcolor("black")  # 填充的颜色
    t.pendown()
    t.begin_fill()
    t.pensize(2)  # 画笔粗细
    t.setheading(45)  # 设置朝向
    t.circle(-100, 60)
    t.left(5)
    t.circle(-175, 20)
    t.left(5)
    t.circle(-40, 20)
    t.right(145)
    t.circle(485, 20)
    t.end_fill()

#左眼睛
    t.penup()  # 起笔
    t.fillcolor("white")  # 填充的颜色
    t.goto(-70, 100)  # 定位开始的坐标
    t.begin_fill()
    t.pendown()
    t.pensize(6)  # 画笔粗细
    t.setheading(120)  # 设置朝向
    t.circle(30, 30)
    t.left(5)
    t.circle(30, 30)
    t.left(3)
    t.circle(50, 30)
    t.left(3)
    t.circle(50, 30)
    t.left(3)
    t.circle(100, 10)
    t.left(3)
    t.circle(100, 10)
    t.left(3)
    t.circle(100, 10)
    t.left(3)
    t.circle(100, 10)
    t.left(3)
    t.circle(30, 10)
    t.left(3)
    t.circle(30, 10)
    t.left(3)
    t.circle(50, 10)
    t.left(3)
    t.circle(30, 10)
    t.left(3)
    t.circle(50, 10)
    t.left(3)
    t.circle(50, 10)
    t.left(3)
    t.circle(50, 10)
    t.left(3)
    t.circle(100, 10)
    t.left(3)
    t.circle(100, 10)
    t.penup()  # 起笔
    t.pensize(1)  # 画笔粗细
    t.pendown()
    t.color("white")
    t.setheading(70)  # 设置朝向
    t.circle(80, 8)
    t.left(2)
    t.circle(80, 8)
    t.left(2)
    t.circle(80, 8)
    t.left(2)
    t.circle(80, 8)
    t.left(2)
    t.circle(80, 8)
    t.left(2)
    t.circle(85, 8)
    t.end_fill()

    # 左眼睛内部
    t.penup()  # 起笔
    t.color("black")
    t.goto(-85, 110)  # 定位开始的坐标
    t.fillcolor("dark orange")  # 填充的颜色
    t.pendown()
    t.begin_fill()
    t.pensize(4)  # 画笔粗细
    t.setheading(-180)  # 设置朝向
    a = 0.04  # 控制椭圆大下短轴
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:  # 控制a的变化
            a = a + 0.12 # 长轴
            t.lt(3)  # 向左转3度
            t.fd(a)  # 向前走a的步长
        else:
            a = a - 0.12
            t.lt(3)
            t.fd(a)

    t.end_fill()

   #左黑眼球
    t.penup()  # 起笔
    t.goto(-82, 100)  # 定位开始的坐标
    t.pendown()
    t.fillcolor("black")  # 填充的颜色
    t.begin_fill()#开始填充
    t.pensize(2)  # 画笔粗细
    t.setheading(-180)  # 设置朝向
    # pen = t.Turtle()  # 定义画笔实例
    a = 0.01#控制椭圆大下短轴
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:  # 控制a的变化
            a = a + 0.09#长轴
            t.lt(3)  # 向左转3度
            t.fd(a)  # 向前走a的步长
        else:
            a = a - 0.09
            t.lt(3)
            t.fd(a)
    t.end_fill()#结束填充
    # t.mainloop()
    # 眼球白点
    t.penup()  # 起笔
    t.goto(-95, 90)  # 定位开始的坐标
    t.pendown()
    t.pensize(1)  # 画笔粗细
    t.fillcolor("white")  # 填充的颜色
    t.begin_fill()  # 开始填充
    t.circle(6)
    t.end_fill()  # 结束填充

    # 右眼
    t.penup()  # 起笔
    t.fillcolor("white")  # 填充的颜色
    t.goto(80, 100)  # 定位开始的坐标
    t.begin_fill()
    t.pendown()
    t.pensize(6)  # 画笔粗细
    t.setheading(50)  # 设置朝向
    t.circle(-30, 20)
    t.right(8)
    t.circle(-50, 20)
    t.right(8)
    t.circle(-50, 20)
    t.right(8)
    t.circle(-50, 20)
    t.right(8)
    t.circle(-80, 20)
    t.right(8)
    t.circle(-80, 20)
    t.right(3)
    t.circle(-80, 20)
    t.right(3)
    t.circle(-30, 20)
    t.right(3)
    t.circle(-30, 20)
    t.right(3)
    t.circle(-30, 20)
    t.right(3)
    t.circle(-30, 20)
    t.right(5)
    t.circle(-90, 20)
    t.pensize(1)
    t.color("white")
    t.right(6)
    t.circle(-90, 20)
    t.right(6)
    t.circle(-90, 20)
    t.end_fill()

    #右眼球
    t.penup()  # 起笔
    t.color("black")
    t.fillcolor("dark orange")  # 填充的颜色
    t.goto(100, 110)  # 定位开始的坐标
    t.begin_fill()
    t.pendown()
    t.pensize(4)  # 画笔粗细
    t.setheading(240)  # 设置朝向
    t.circle(100, 20)
    t.left(3)
    t.circle(80, 20)
    t.left(3)
    t.circle(50, 20)
    t.left(3)
    t.circle(20, 20)
    t.left(3)
    t.circle(20, 20)
    t.left(3)
    t.circle(30, 20)
    t.left(3)
    t.circle(30, 20)
    t.left(3)
    t.circle(30, 20)
    t.left(1)
    t.circle(30, 20)
    t.left(0.1)
    t.pensize(2)
    t.circle(80, 10)
    t.left(0.1)
    t.circle(80, 10)
    t.left(0.1)
    t.circle(80, 10)
    t.left(0.5)
    t.circle(50, 10)
    t.left(0.5)
    t.circle(50, 10)
    t.end_fill()

    # 右黑眼球
    t.penup()  # 起笔
    t.goto(120, 110)  # 定位开始的坐标
    t.pendown()
    t.fillcolor("black")  # 填充的颜色
    t.begin_fill()  # 开始填充
    t.pensize(2)  # 画笔粗细
    t.setheading(-180)  # 设置朝向
    # pen = t.Turtle()  # 定义画笔实例
    a = 0.01  # 控制椭圆大下短轴
    for i in range(120):
        if 0 <= i < 30 or 60 <= i < 90:  # 控制a的变化
            a = a + 0.09  # 长轴
            t.lt(3)  # 向左转3度
            t.fd(a)  # 向前走a的步长
        else:
            a = a - 0.09
            t.lt(3)
            t.fd(a)
    t.end_fill()  # 结束填充
    # t.mainloop()
    # 右眼球白点
    t.penup()  # 起笔
    t.goto(105, 90)  # 定位开始的坐标
    t.pendown()
    t.pensize(1)  # 画笔粗细
    t.fillcolor("white")  # 填充的颜色
    t.begin_fill()  # 开始填充
    t.circle(6)
    t.end_fill()  # 结束填充
    #鼻子
    t.penup()  # 起笔
    t.goto(65, 45)  # 定位开始的坐标
    t.pendown()
    t.pensize(8)  # 画笔粗细
    t.forward(100)

    t.penup()  # 起笔
    t.goto(65, 35)  # 定位开始的坐标
    t.pendown()
    t.fillcolor("black")  # 填充的颜色
    t.pensize(5)  # 画笔粗细
    t.begin_fill()
    t.forward(80)
    t.left(145)
    t.forward(50)
    t.left(-289)
    t.forward(50)
    t.end_fill()

    #嘴巴
    t.penup()  # 起笔
    t.goto(25, 30)  # 定位开始的坐标
    t.pendown()
    t.pensize(7)  # 画笔粗细
    t.setheading(270)
    t.forward(40)
    t.pensize(7)  # 画笔粗细
    t.left(30)
    t.forward(50)
    #
    t.penup()  # 起笔
    t.goto(22, -10)  # 定位开始的坐标
    t.pendown()
    t.pensize(7)  # 画笔粗细
    t.left(-65)
    t.forward(80)
#胡须
    t.penup()  # 起笔
    t.goto(-5, -15)  # 定位开始的坐标
    t.pendown()
    t.pensize(7)  # 画笔粗细
    t.setheading(-195)
    t.left(3)
    t.circle(300, 10)
    t.left(3)
    t.circle(300, 10)
    t.left(3)
    t.circle(300, 10)
    t.left(3)
    t.circle(300, 10)

    t.penup()  # 起笔
    t.goto(-25, -35)  # 定位开始的坐标
    t.pendown()
    t.pensize(7)  # 画笔粗细
    t.setheading(-180)
    t.left(5)
    t.circle(500, 10)
    t.left(5)
    t.circle(500, 10)

    t.penup()  # 起笔
    t.goto(55, -15)  # 定位开始的坐标
    t.pendown()
    t.pensize(7)  # 画笔粗细
    t.setheading(10)
    t.right(5)
    t.circle(-300, 10)
    t.right(5)
    t.circle(-300, 10)
    t.right(5)
    t.circle(-300, 10)

    t.penup()  # 起笔
    t.goto(55, -35)  # 定位开始的坐标
    t.pendown()
    t.pensize(7)  # 画笔粗细
    t.setheading(-10)
    t.right(5)
    t.circle(-500, 10)
    t.right(5)
    t.circle(-300, 10)
###
    t.penup()  # 起笔
    t.goto(-100, -10)  # 定位开始的坐标
    t.fillcolor("black")
    t.begin_fill()
    t.pendown()
    t.pensize(1)  # 画笔粗细
    t.setheading(-105)
    t.circle(100, 15)
    t.left(15)
    t.circle(100, 15)

    t.right(140)
    t.circle(-60, 15)
    t.right(15)
    t.circle(-60, 15)
    t.right(15)
    t.circle(-60, 15)
    t.right(15)
    t.circle(-60, 15)
    t.right(15)
    t.circle(-60, 15)
    t.end_fill()

    ###左
    t.penup()  # 起笔
    t.goto(-130, -14)  # 定位开始的坐标
    t.fillcolor("black")
    t.begin_fill()
    t.pendown()
    t.pensize(1)  # 画笔粗细
    t.setheading(-130)
    t.circle(50, 15)
    t.left(5)
    t.circle(50, 15)
    t.left(5)
    t.circle(60, 15)
    t.left(5)
    t.circle(60, 15)
    t.left(5)
    t.circle(60, 15)

    t.right(140)
    t.circle(-50, 15)
    t.right(5)
    t.circle(-50, 15)
    t.right(5)
    t.circle(-50, 15)
    t.right(5)
    t.circle(-50, 15)
    t.right(15)
    t.circle(-60, 15)
    t.right(15)
    t.circle(-80, 15)
    t.right(15)
    t.circle(-80, 15)
    t.end_fill()
    ###右
    t.penup()  # 起笔
    t.goto(140, 5)  # 定位开始的坐标
    t.fillcolor("black")
    t.begin_fill()
    t.pendown()
    t.pensize(1)  # 画笔粗细
    t.setheading(-25)
    t.forward(20)
    t.circle(-100, 10)
    t.right(0.1)
    t.circle(-100, 10)
    t.right(0.1)
    t.circle(-100, 10)

    t.right(80)
    t.forward(40)
    t.right(140)
    t.circle(80, 20)
    t.right(3)
    t.circle(80, 20)
    t.end_fill()

    t.penup()  # 起笔
    t.goto(130, -10)  # 定位开始的坐标
    t.fillcolor("black")
    t.begin_fill()
    t.pendown()
    t.pensize(1)  # 画笔粗细
    t.setheading(-50)
    t.forward(20)
    t.circle(-50, 10)
    t.right(10)
    t.circle(-50, 10)
    t.right(10)
    t.circle(-50, 10)
    t.right(10)
    t.circle(-50, 10)
    t.right(10)
    t.circle(-50, 10)
    t.right(10)
    t.circle(-50, 10)
    t.right(10)
    t.circle(-50, 10)

    t.right(120)
    t.circle(60, 20)
    t.right(3)
    t.circle(60, 20)
    t.right(3)
    t.circle(60, 20)
    t.end_fill()
##左手
    # t.penup()  # 起笔
    # t.goto(-130, -100)  # 定位开始的坐标
    # t.fillcolor("black")
    # t.begin_fill()
    # t.pendown()
    # t.pensize(10)  # 画笔粗细
    # t.setheading(260)
    # t.circle(200, 15)
    # t.left(5)
    # t.circle(200, 15)
    # t.left(5)
    # t.circle(200, 15)
    # t.left(5)
    # t.circle(200, 15)
    # t.left(5)
    # t.circle(200, 15)
    # t.left(25)
    # t.circle(100, 15)


    t.exitonclick()  # 点击画面时画布才会消失


if __name__ == '__main__':
    tiger()

  拿来做个壁纸还是很不错的,自己动手丰衣足食。

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

TC_zyq

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值