【python】——turtle动态画

🎃个人专栏:

🐬 算法设计与分析:算法设计与分析_IT闫的博客-CSDN博客

🐳Java基础:Java基础_IT闫的博客-CSDN博客

🐋c语言:c语言_IT闫的博客-CSDN博客

🐟MySQL:数据结构_IT闫的博客-CSDN博客

🐠数据结构:​​​​​​数据结构_IT闫的博客-CSDN博客

💎C++:C++_IT闫的博客-CSDN博客

🥽C51单片机:C51单片机(STC89C516)_IT闫的博客-CSDN博客

💻基于HTML5的网页设计及应用:基于HTML5的网页设计及应用_IT闫的博客-CSDN博客​​​​​​

🥏python:python_IT闫的博客-CSDN博客

🐠离散数学:离散数学_IT闫的博客-CSDN博客

欢迎收看,希望对大家有用!

目录

🎯turtle动态小老虎:

🎃代码功能:

🎃实现代码:

🎃实现效果:

 🎯turtle动态小老虎:

🎃代码功能:

🎃分布解析该代码:

🎃实现代码:

🎃 实现效果:


🎯turtle动态小老虎:

🎃代码功能:

使用Python的turtle库绘制了一个小老虎的图形。它能够实现绘制小老虎的头部、面部、眼睛、鼻子、嘴巴、耳朵、帽子、眉毛、阴影、身体、胡须、左手、右手、衣服、尾巴和鼓等功能。通过调用不同的函数来绘制不同部分的图形,最终完成了一个可爱的小老虎的图形。


🎃实现代码:

# coding=utf-8
from turtle import *
import timeCOLOR = '#B2814D'def set_start(x, y, w, c=COLOR):penup()setx(x)sety(y)setheading(towards(0, 0))width(w)pencolor(c)pendown()speed(0)def left_rotate(time, angle, length):for i in range(time):left(angle)forward(length)def right_rotate(time, angle, length):for i in range(time):right(angle)forward(length)def draw_circle(radius, color, color2=''):if color2 == '':color2 = colorpenup()setheading(towards(0, 0))right(90)pencolor(color)pendown()begin_fill()circle(radius)fillcolor(color2)end_fill()def fill_color(color):def decorator_all(func):def wrapper(*args, **kwargs):begin_fill()func(*args, **kwargs)fillcolor(color)end_fill()return wrapperreturn decorator_alldef fill_color_patch(x, y, c='#fffffb'):set_start(x, y, 1, c=c)forward(1)def head_outline():set_start(0, -40, 2.5)right(90)left_rotate(5, 3, 14)left_rotate(5, 8, 8)left_rotate(10, 5, 6.5)left_rotate(5, 5.5, 10)left_rotate(25, 4, 10)left_rotate(6, 5.5, 5)left_rotate(7, 3, 7)left_rotate(5, 10, 8)left_rotate(5, 3, 14)@fill_color('#fdb933')
def draw_head():head_outline()pencolor('#CDCDCD')goto(0, -40)@fill_color('#fffffb')
def draw_face():set_start(0, -40, 2.5)right(90)left_rotate(5, 3, 14)left_rotate(1, 80, 2.5)pencolor('#fffffb')left_rotate(12, 5, 6.5)left_rotate(5, 6, 15)left_rotate(5, 5, 10)left_rotate(5, 12, 10)backward(0.5)left(65)pencolor(COLOR)backward(3)left_rotate(5, 3, 14)forward(5)def draw_moustache():fill_color_patch(-41, -31)begin_fill()set_start(-41, -31, 2.5)right(180)left_rotate(4, 20, 4)left_rotate(1, 90, 8)right(150)left_rotate(4, 25, 3)forward(6)left_rotate(1, 110, 5.5)right(165)left_rotate(4, 15, 3.2)left(150)right_rotate(3, 30, 2.2)right_rotate(1, 105, 5)left(130)right_rotate(6, 5, 1.8)right_rotate(1, 130, 2)left(60)left_rotate(2, 30, 1)left_rotate(4, 28, 4)fillcolor('#fffffb')end_fill()set_start(-45, -28, 2.5)right(70)left_rotate(5, 2.5, 4)left_rotate(4, 9, 3)left_rotate(5, 3, 4.5)def draw_mouth():set_start(-17, 22, 2.5)right_rotate(1, 45, 14)left_rotate(1, 85, 35)left_rotate(1, 70, 7)set_start(-17, 22, 2.5)right_rotate(1, 45, 14)right_rotate(1, 78, 36)right_rotate(1, 65, 6)set_start(-17, 22, 2.5)right_rotate(1, 45, 14)left_rotate(1, 85, 30)right_rotate(1, 108, 12)right_rotate(1, 140, 5)set_start(-17, 22, 2.5)right_rotate(1, 45, 14)right_rotate(1, 75, 28)left_rotate(1, 85, 10)left_rotate(1, 130, 8)set_start(3, 0, 2.5)left(90)right_rotate(5, 5, 4.8)right_rotate(4, 18, 1.8)left_rotate(1, 3, 27)right_rotate(4, 18, 1)right_rotate(1, 15, 22)right(88)right_rotate(9, 1, 4.5)begin_fill()set_start(3, 0, 2.5)left(90)right_rotate(4, 5, 4.8)right_rotate(1, 5, 2)right_rotate(1, 67, 37)right_rotate(1, 86, 18)fillcolor('#f15a22')end_fill()begin_fill()set_start(3, 0, 2.5)pencolor('#aa2116')left(90)right_rotate(2, 5, 6)right(120)left_rotate(10, 6, 2)right(55)left_rotate(11, 5.5, 1.8)right_rotate(1, 110, 10)right(100)right_rotate(9, 1, 4.5)fillcolor('#aa2116')end_fill()set_start(3, 0, 2.5)left(90)right_rotate(5, 5, 4.8)right_rotate(4, 18, 1.8)left_rotate(1, 3, 27)right_rotate(4, 18, 1)right_rotate(1, 15, 22)right(88)right_rotate(9, 1, 4.5)set_start(21, 10, 1, c='#fdb933')draw_circle(2.3, '#fdb933')set_start(10, 16, 1, c='#fdb933')draw_circle(2.3, '#fdb933')set_start(21, 19, 1, c='#fdb933')draw_circle(2.3, '#fdb933')set_start(-57, 16, 1, c='#fdb933')draw_circle(2.3, '#fdb933')set_start(-51, 24, 1, c='#fdb933')draw_circle(2.3, '#fdb933')set_start(-64, 24, 1, c='#fdb933')draw_circle(2.3, '#fdb933')def draw_nose():set_start(6, 37, 1)pencolor('#e0861a')right(150)begin_fill()left_rotate(6, 3, 4)left_rotate(6, 15, 3)left_rotate(6, 3, 4)fillcolor('#e0861a')end_fill()set_start(6, 37, 1.5)right(120)begin_fill()left_rotate(5, 4, 4)left_rotate(3, 10, 3)left_rotate(5, 4, 4)left_rotate(7, 15, 0.8)left_rotate(5, 4, 4)left_rotate(5, 8, 2)left_rotate(5, 4, 4)left_rotate(7, 15, 0.8)fillcolor('#b4532a')end_fill()set_start(-16, 36, 1)pencolor('#d1923f')right(75)begin_fill()right_rotate(4, 15, 2)right_rotate(5, 26, 1)right_rotate(4, 15, 2)right_rotate(5, 26, 1)fillcolor('#d1923f')end_fill()set_start(-25, 25, 1)pencolor('#130c0e')left(110)begin_fill()left_rotate(6, 15, 1.5)left_rotate(5, 15, 1)fillcolor('#130c0e')end_fill()set_start(-10, 24, 1)pencolor('#130c0e')left(175)begin_fill()right_rotate(6, 15, 1.2)right_rotate(5, 15, 1)fillcolor('#130c0e')end_fill()def draw_eye():set_start(-50, 34, 1, c='#130c0e')left(115)begin_fill()left_rotate(8, 6.5, 7)left_rotate(5, 15, 7)left_rotate(5, 10, 5.5)left_rotate(5, 15, 6)left_rotate(5, 5, 9.5)left_rotate(4, 30, 2)fillcolor('#130c0e')end_fill()set_start(-57, 40, 1, c='#fffffb')left(112)begin_fill()left_rotate(8, 6.5, 5)left_rotate(5, 15, 6)left_rotate(5, 10, 4.5)left_rotate(5, 15, 5)left_rotate(5, 6.5, 7)left_rotate(4, 15, 2)fillcolor('#fffffb')end_fill()set_start(-90, 62, 1, c='#563624')draw_circle(15, '#563624')set_start(-84, 59, 1, c='#130c0e')draw_circle(9, '#130c0e')set_start(-90, 63, 1, c='#fffffb')draw_circle(3.5, '#fffffb')set_start(16, 25, 1, c='#130c0e')right(150)begin_fill()right_rotate(8, 6.5, 7)right_rotate(5, 15, 7)right_rotate(5, 10, 5.5)right_rotate(5, 15, 6)right_rotate(5, 5, 9.5)right_rotate(4, 30, 2)fillcolor('#130c0e')end_fill()set_start(24, 28, 1, c='#fffffb')right(135)begin_fill()right_rotate(8, 7, 5)right_rotate(5, 15, 5.5)right_rotate(5, 10, 4.5)right_rotate(5, 15, 4.5)right_rotate(5, 6.5, 6.5)right_rotate(4, 13, 2)fillcolor('#fffffb')end_fill()set_start(57, 48, 1, c='#563624')draw_circle(15, '#563624')set_start(53, 44, 1, c='#130c0e')draw_circle(9, '#130c0e')set_start(38, 47, 1, c='#fffffb')draw_circle(3.5, '#fffffb')def draw_brow():set_start(12, 88, 1, c='#130c0e')right(82)begin_fill()left_rotate(3, 3, 5)right_rotate(5, 4, 6)right_rotate(7, 24, 2.3)right_rotate(3, 5, 4.5)left_rotate(1, 90, 8)left(95)left_rotate(3, 8, 5)right_rotate(3, 25, 1.2)right_rotate(3, 11, 1.5)right_rotate(3, 25, 1.2)right_rotate(3, 3, 4.5)left_rotate(1, 85, 7)left_rotate(1, 90, 15)right_rotate(5, 30, 2.2)right_rotate(3, 9, 6)right_rotate(6, 3, 5)right_rotate(8, 18, 1.3)right_rotate(3, 10, 5.3)left_rotate(1, 90, 8)left(112)right_rotate(3, 3, 4.5)right_rotate(3, 25, 1)right_rotate(3, 10, 1.5)right_rotate(3, 28, 1)left_rotate(3, 5, 3)left_rotate(3, 25, 1)left_rotate(3, 5, 1.8)left_rotate(1, 90, 17)right_rotate(3, 35, 0.8)right_rotate(3, 10, 3)fillcolor('#130c0e')end_fill()set_start(88, -16, 1, c='#130c0e')begin_fill()right_rotate(5, 15, 3)right_rotate(4, 5.5, 3)right_rotate(3, 28, 1)right_rotate(5, 6, 4)fillcolor('#130c0e')end_fill()set_start(106, 9, 1, c='#130c0e')right(15)begin_fill()right_rotate(5, 5, 5.5)right_rotate(5, 29, 3)right_rotate(5, 5, 4.5)fillcolor('#130c0e')end_fill()set_start(110, 36, 1, c='#130c0e')left(20)begin_fill()right_rotate(3, 10, 2)right_rotate(3, 10, 6)right_rotate(5, 29, 2)forward(20)fillcolor('#130c0e')end_fill()set_start(75, 76, 1, c='#130c0e')right(105)begin_fill()left_rotate(5, 10, 4)right_rotate(6, 28, 2)right_rotate(5, 10, 5)right_rotate(6, 25, 2)fillcolor('#130c0e')end_fill()set_start(-75, 100, 1, c='#130c0e')right(108)begin_fill()right_rotate(3, 3, 8)right_rotate(4, 35, 2)right_rotate(8, 9, 3.2)fillcolor('#130c0e')end_fill()set_start(-145, 58, 1, c='#130c0e')right(30)begin_fill()left_rotate(5, 15, 5)left_rotate(3, 18, 3)left(92)right_rotate(4, 5, 6)right_rotate(1, 5, 4)fillcolor('#130c0e')end_fill()set_start(-148, 46, 1, c='#130c0e')left(40)begin_fill()right_rotate(5, 10, 6.5)right_rotate(4, 32, 2)right_rotate(4, 10, 6.5)fillcolor('#130c0e')end_fill()set_start(-138, 7, 1, c='#130c0e')left(10)begin_fill()left_rotate(5, 8, 4)left_rotate(6, 20, 1.5)left_rotate(4, 8, 4.5)fillcolor('#130c0e')end_fill()head_outline()def draw_ear():set_start(101, 74, 2.5)left(150)begin_fill()left_rotate(5, 6, 3)left_rotate(5, 12, 5)left_rotate(3, 13, 12)left_rotate(5, 12, 7)left_rotate(4, 16, 5)fillcolor('#fdb933')end_fill()set_start(94, 89, 1, c='#f3715c')right(168)begin_fill()left_rotate(5, 17, 6)left_rotate(4, 20, 5)goto(94, 89)fillcolor('#f3715c')end_fill()set_start(-125, 98, 2.5)right(165)begin_fill()right_rotate(5, 6, 3)right_rotate(5, 12, 5)right_rotate(3, 13, 12)right_rotate(5, 12, 7)right_rotate(4, 16, 4.5)fillcolor('#fdb933')end_fill()set_start(-115, 110, 1, c='#f3715c')left(160)begin_fill()right_rotate(5, 17, 6)right_rotate(4, 20, 5.5)goto(-115, 110)fillcolor('#f3715c')end_fill()head_outline()def draw_cap():set_start(55, 123, 2.5)right(150)left_rotate(13, 11, 12)set_start(18, 170, 2.5)right(180)begin_fill()left_rotate(10, 16, 4)fillcolor('#130c0e')end_fill()set_start(55, 123, 2.5)right(150)begin_fill()left_rotate(13, 11, 12)fillcolor('#FF0000')end_fill()set_start(55, 123, 2.5)right(113)begin_fill()left_rotate(15, 5, 8.6)fillcolor('#228B22')end_fill()set_start(30, 142, 2.5)right(170)left_rotate(18, 8.9, 5)set_start(-2, 150, 2.5)left(178)right_rotate(4, 5, 6)set_start(55, 123, 2.5)begin_fill()goto(50.13, 124.56)setheading(148.5)left_rotate(12, 4, 10)fillcolor('#fdb933')end_fill()def draw_shadow():fill_color_patch(75, -155)_draw_shadow()@fill_color('#fab27b')
def _draw_shadow():set_start(75, -155, 1, c='#fab27b')left_rotate(5, 8, 5)left_rotate(10, 4, 10)left_rotate(5, 6, 9)left_rotate(4, 30, 4.5)left_rotate(5, 3.5, 16)left_rotate(3, 3.5, 18)left_rotate(3, 8, 5)left_rotate(4, 20, 1.5)goto(75, -155)def draw_body():fill_color_patch(0, -40)set_start(0, -40, 2.5)right(90)begin_fill()left_rotate(2, 3, 14)width(2.4)goto(53, -74)pencolor('#87481f')left(20)right_rotate(5, 16, 1.3)right_rotate(4, 8, 8)right_rotate(1, 15, 2)right_rotate(1, 30, 7)right_rotate(3, 28, 2)right_rotate(1, 5, 4)right_rotate(1, 90, 6)right_rotate(1, 180, 10)right_rotate(3, 5, 8)right_rotate(3, 10, 6.5)right_rotate(2, 15, 2)right_rotate(4, 7, 4.5)left_rotate(2, 18, 1)left_rotate(4, 12, 5)left_rotate(4, 15, 3)left_rotate(4, 7, 4)right_rotate(1, 82, 2)right_rotate(4, 8, 7)right_rotate(2, 12, 2)right_rotate(4, 28, 1.5)right_rotate(1, 10, 6)right_rotate(1, 60, 4.5)right(170)right_rotate(5, 10, 5)right_rotate(10, 2.5, 5)goto(-71.81, -32.68)setheading(345.5)width(2.5)pencolor(COLOR)left_rotate(2, 3, 14)fillcolor('#fdb933')end_fill()set_start(0, -42, 1)right(90)pencolor('#fffffb')begin_fill()right_rotate(5, 12, 5)right_rotate(3, 13, 15)right_rotate(3, 25, 12)backward(1)right(23)left_rotate(3, 15, 6)right(5)right_rotate(3, 20, 11)right_rotate(3, 15, 12)right_rotate(3, 15, 10)right_rotate(1, 15, 20)fillcolor('#fffffb')end_fill()set_start(37, -125, 1)pencolor('#130c0e')begin_fill()right_rotate(1, 5, 8)right_rotate(4, 30, 1.5)right_rotate(1, 20, 6)fillcolor('#130c0e')end_fill()set_start(29, -130, 1)pencolor('#130c0e')begin_fill()left(20)right_rotate(2, 5, 5)left_rotate(4, 30, 1.5)left_rotate(2, 10, 4)right_rotate(3, 20, 2)left(155)left_rotate(3, 8, 5)fillcolor('#130c0e')end_fill()set_start(-62, -139, 1)pencolor('#130c0e')begin_fill()right(65)left_rotate(2, 10, 4)left_rotate(3, 25, 1.5)left_rotate(1, 10, 2)left_rotate(3, 28, 1.5)right_rotate(3, 10, 3.5)fillcolor('#130c0e')end_fill()set_start(-71, -118, 1)pencolor('#130c0e')begin_fill()right(50)left_rotate(4, 10, 2.5)left_rotate(5, 28, 1.5)right_rotate(3, 10, 2.5)fillcolor('#130c0e')end_fill()set_start(-75, -94, 1)pencolor('#130c0e')begin_fill()right(30)left_rotate(4, 10, 2.5)left_rotate(5, 28, 1.5)right_rotate(3, 10, 2.5)fillcolor('#130c0e')end_fill()def draw_left_hand():set_start(0, -40, 2.5)right(90)left_rotate(4, 3, 14)left_rotate(1, 3, 8)right_rotate(1, 33, 3)begin_fill()left_rotate(1, 0, 4)left_rotate(3, 7, 7)left_rotate(4, 18, 3.8)set_start(103, -26, 2.5)right_rotate(3, 20, 4.5)right_rotate(3, 20, 2.5)right_rotate(2, 20, 2)right_rotate(2, 18, 5)right_rotate(5, 30, 1.5)right_rotate(1, 5, 8)right_rotate(1, 180, 2)right_rotate(2, 40, 3.5)set_start(106, -8, 2.5)right(90)right_rotate(2, 10, 4)right_rotate(4, 24, 3)right_rotate(2, 10, 4)right_rotate(2, 20, 5)right_rotate(5, 26, 1.2)right_rotate(2, 10, 4)right_rotate(1, 190, 4)right_rotate(1, 90, 3)set_start(128, -12, 2.5)left(155)right_rotate(3, 20, 5.5)right_rotate(2, 25, 1.5)right_rotate(1, 25, 4)right_rotate(3, 25, 2)right_rotate(2, 10, 3)set_start(124, -30, 2.5)left(150)right_rotate(8, 25, 2)right_rotate(1, 15, 3)right_rotate(2, 28, 2)set_start(115, -35, 2.5)left(100)right_rotate(5, 26, 1.8)right_rotate(1, 25, 5)set_start(103, -31, 2.5)left(135)right_rotate(5, 10, 5)right_rotate(4, 15, 6)left_rotate(1, 100, 7)right(120)right_rotate(3, 12, 2.5)left(170)right_rotate(3, 15, 3)right(110)right_rotate(3, 12, 3)left(140)right_rotate(3, 12, 3)right(120)right_rotate(3, 10, 3.5)left_rotate(1, 125, 10)right_rotate(3, 23, 3)right_rotate(3, 9, 9.5)fillcolor('#fdb933')end_fill()set_start(115, -35, 2.5)left(100)begin_fill()right_rotate(5, 26, 1.8)right_rotate(1, 25, 5)pencolor('#fffffb')width(1)left(90)right_rotate(4, 40, 2)left(90)right_rotate(4, 40, 1)left_rotate(1, 135, 5)right(80)right_rotate(3, 26, 4.5)right(130)left_rotate(3, 28, 3)fillcolor('#fffffb')end_fill()set_start(61, -33, 1)left(118)pencolor('#130c0e')begin_fill()right_rotate(3, 5, 3.5)right_rotate(4, 32, 1.5)right_rotate(3, 12, 2.7)fillcolor('#130c0e')end_fill()set_start(78, -36, 1)left(110)pencolor('#130c0e')begin_fill()left_rotate(3, 5, 3.5)right(50)right_rotate(4, 20, 1)right_rotate(5, 10, 3)fillcolor('#130c0e')end_fill()set_start(94, -35, 1)left(125)pencolor('#130c0e')begin_fill()left_rotate(3, 5, 2)right(50)right_rotate(4, 25, 2)right_rotate(3, 10, 2.2)fillcolor('#130c0e')end_fill()def draw_right_hand():fill_color_patch(-44.24, -37.54)set_start(-44.24, -37.54, 2.5)setheading(351.5)begin_fill()right(177)right_rotate(4, 3, 14)right(3)goto(-106, -22)set_start(-106, -22, 2.5)right(175)right_rotate(3, 5, 5.5)right_rotate(3, 22, 4)right(80)left_rotate(2, 25, 4)left_rotate(4, 35, 5.5)left_rotate(3, 30, 1.5)left_rotate(3, 20, 2)left_rotate(1, 10, 2.5)right(120)left_rotate(3, 20, 2.5)set_start(-143, -2, 2.5)left(120)left_rotate(4, 25, 3.5)left_rotate(1, 35, 3)left_rotate(2, 15, 3)left_rotate(5, 22, 3.5)left_rotate(2, 20, 2.5)set_start(-155, -7, 2.5)left(170)left_rotate(2, 35, 3.5)left_rotate(2, 12, 4.5)left_rotate(3, 28, 4)left_rotate(3, 10, 3)left_rotate(3, 28, 3.5)set_start(-158, -27, 2.5)right(130)left_rotate(3, 30, 2.5)left_rotate(4, 13, 4)left_rotate(4, 35, 2.5)set_start(-135, -25, 2.5)right(95)left_rotate(3, 12, 9)left_rotate(4, 12, 4)right_rotate(1, 90, 8)left(120)left_rotate(3, 12, 3)right(160)left_rotate(3, 10, 4)left(120)left_rotate(3, 12, 3.5)right(145)left_rotate(3, 10, 3.5)left(125)left_rotate(3, 10, 3.5)right_rotate(1, 135, 10)fillcolor('#fdb933')end_fill()fill_color_patch(-107, -23)begin_fill()set_start(-107, -23, 1)pencolor('#130c0e')right(90)right_rotate(3, 3, 3.5)left_rotate(5, 25, 1)left_rotate(3, 15, 3.2)fillcolor('#130c0e')end_fill()fill_color_patch(-122, -25)begin_fill()set_start(-122, -25, 1)pencolor('#130c0e')right(120)left_rotate(3, 5, 2)left_rotate(4, 30, 1.4)left_rotate(3, 15, 3)fillcolor('#130c0e')end_fill()def draw_clothes():set_start(0, -40, 2.5)right(90)begin_fill()left_rotate(3, 3, 14)goto(47.57, -36.43)setheading(94.25)left(171)left_rotate(3, 9, 9.5)left_rotate(1, 9, 3)left_rotate(2, 23, 2.5)right(150)left_rotate(3, 10, 5)right_rotate(3, 10, 10)right_rotate(1, 20, 4)right_rotate(2, 10, 4)right(90)left_rotate(5, 5, 10)fillcolor('#FF0000')end_fill()set_start(0, -40, 2.5)right(90)begin_fill()left_rotate(1, 3, 14)left_rotate(1, 3, 13)right(88)right_rotate(5, 5, 10)goto(21.85, -91.11)setheading(197.25)right_rotate(1, 20, 4)right_rotate(2, 10, 4)right(90)left_rotate(5, 5, 10)fillcolor('#228B22')end_fill()set_start(-44.24, -37.54, 2.5)setheading(351.5)begin_fill()right(177)right_rotate(2, 3, 14)right_rotate(1, 3, 7)left(65)left_rotate(4, 7, 10)left_rotate(3, 6, 10)left_rotate(1, 0, 2)left(128)right_rotate(6, 7, 6.1)right_rotate(2, 7, 6.1)left(125)right_rotate(5, 4, 11)fillcolor('#FF0000')end_fill()set_start(-44.24, -37.54, 2.5)setheading(351.5)begin_fill()right(177)right_rotate(1, 3, 14)right_rotate(1, 3, 8)left(92)left_rotate(4, 8, 7)right(10)right_rotate(4, 3, 6)goto(-59.29, -87.30)setheading(2.5)right_rotate(2, 7, 6.1)left(125)right_rotate(5, 4, 11)fillcolor('#228B22')end_fill()def draw_tail():set_start(53, -74, 2.4, c='#87481f')begin_fill()setheading(26)right_rotate(5, 16, 1.3)right_rotate(1, 8, 8)right_rotate(1, 8, 4)left(60)right_rotate(1, 3, 3)pencolor(COLOR)forward(5)right_rotate(4, 3, 8)left_rotate(3, 3, 7)left_rotate(2, 5, 3)left_rotate(5, 6, 6)left_rotate(3, 8, 7)left_rotate(5, 12, 6)left_rotate(5, 10, 6)left_rotate(5, 15, 2)left_rotate(2, 20, 2)left_rotate(3, 10, 3)right_rotate(2, 13, 5)right_rotate(2, 20, 6)right_rotate(2, 12, 6)right_rotate(5, 7.5, 5)right_rotate(6, 3, 4)left_rotate(4, 2, 8.5)fillcolor('#fdb933')end_fill()set_start(53, -74, 2.4, c='#87481f')begin_fill()setheading(26)right_rotate(5, 16, 1.3)right_rotate(1, 8, 8)right_rotate(1, 8, 3)left(60)right_rotate(1, 3, 2)pencolor('#130c0e')left_rotate(3, 25, 2)left_rotate(3, 5, 1.8)left_rotate(1, 78, 8.5)fillcolor('#130c0e')end_fill()set_start(83, -81, 1, c='#130c0e')begin_fill()left(140)right_rotate(5, 8, 2)left_rotate(1, 105, 5)right_rotate(2, 3, 5.5)left(50)left_rotate(3, 15, 4.1)fillcolor('#130c0e')end_fill()set_start(109, -89, 1, c='#130c0e')begin_fill()left(150)right_rotate(3, 5, 2)right_rotate(4, 15, 2)left_rotate(1, 125, 6)left_rotate(2, 3, 7)left(85)left_rotate(3, 15, 6.05)left(68)right_rotate(3, 5, 5)fillcolor('#130c0e')end_fill()set_start(132, -88, 1, c='#130c0e')begin_fill()left(180)right_rotate(5, 10, 4.1)left_rotate(1, 100, 6)left_rotate(2, 5, 7)left(75)left_rotate(5, 10, 5)left(75)right_rotate(3, 8, 4.5)fillcolor('#130c0e')end_fill()set_start(150, -71, 1, c='#130c0e')begin_fill()right(140)right_rotate(5, 15, 5.8)left_rotate(1, 130, 6)left_rotate(2, 10, 5)left(30)left_rotate(5, 15, 5.6)left(81)right_rotate(3, 8, 3)fillcolor('#130c0e')end_fill()set_start(147, -51, 1, c='#130c0e')begin_fill()right(125)right_rotate(5, 10, 4)left(145)left_rotate(2, 10, 6.5)left_rotate(6, 14, 2)left_rotate(4, 22, 2)fillcolor('#130c0e')end_fill()def draw_drum():set_start(-136, -12, 2, c='#87481f')begin_fill()right_rotate(1, 78, 17)right_rotate(5, 30, 1.2)right_rotate(1, 30, 17)fillcolor('#FF0000')end_fill()set_start(-140, -2, 2, c='#87481f')begin_fill()left_rotate(1, 108, 10)right_rotate(1, 90, 4)left_rotate(5, 16, 7)left_rotate(5, 19, 6.5)forward(4)left_rotate(5, 18, 7.5)left_rotate(5, 18, 6.1)left_rotate(1, 180, 3)left_rotate(1, 95, 10)fillcolor('#FF0000')end_fill()set_start(-156.34, 48.19, 1, c='#87481f')setheading(199)left(12)left_rotate(10, 14.5, 5.8)set_start(-140, 12, 1, c='#87481f')setheading(20)begin_fill()left_rotate(5, 14, 5.2)left_rotate(3, 15, 4.5)left_rotate(5, 18, 5)left_rotate(5, 16, 5.5)left_rotate(3, 18, 5)fillcolor('#fffffb')end_fill()set_start(-143, 14, 2.5, c='#FF0000')left_rotate(1, 117, 17)left_rotate(1, 90, 9)left(90)left_rotate(3, 5, 3.5)set_start(-146.8, 14, 2.5, c='#FF0000')left_rotate(1, 120, 14)set_start(-150, 34, 2.5, c='#FF0000')left_rotate(1, 120, 8.5)left(100)left_rotate(3, 17, 4)set_start(-140, 16, 2.5, c='#FF0000')left_rotate(1, 115, 14)right_rotate(1, 90, 13)right(90)right_rotate(4, 16, 4.5)set_start(-136, 18, 2.4, c='#FF0000')left_rotate(1, 112, 12)set_start(-142, 24, 2.5, c='#FF0000')left_rotate(1, 35, 10)set_start(-145, 32, 2.5, c='#FF0000')left_rotate(1, 115, 6)right_rotate(1, 85, 10)right(40)right_rotate(3, 18, 2)right_rotate(1, 95, 10)set_start(-149, 44, 2.5, c='#FF0000')left(60)right_rotate(3, 22, 3)set_start(-166, 20, 2.4)right(100)right_rotate(4, 32, 3)right_rotate(2, 12, 3.5)left_rotate(2, 10, 4)left_rotate(4, 25, 2.5)set_start(-196, 35, 2.4)draw_circle(3.5, COLOR, '#FF0000')set_start(-127, 38, 2.4)left(60)right_rotate(4, 32, 3)right_rotate(2, 12, 3.5)left_rotate(6, 28, 2)left_rotate(3, 15, 2)set_start(-115, 33, 2.4)draw_circle(3.5, COLOR, '#FF0000')if __name__ == '__main__':title('小老虎')setup(420, 400, 150, 150)screensize(400, 380, '#FFE4E1')time.sleep(3)draw_head()draw_face()draw_eye()draw_nose()draw_mouth()draw_ear()draw_cap()draw_brow()draw_shadow()draw_body()draw_moustache()draw_left_hand()draw_right_hand()draw_clothes()draw_tail()draw_drum()set_start(1000, 1000, 2.5)done()

 

使用Python的turtle库绘制一个小老虎的图形。代码分为多个函数,每个函数负责绘制不同部分的图形。

首先,代码定义了一些常量和颜色。然后定义了一个名为set_start的函数,用于设置绘制起点的位置和属性。

接下来,代码定义了左旋转和右旋转的函数,用于控制画笔的旋转方向和移动距离。

之后,定义了绘制圆形的函数和填充颜色的装饰器函数。装饰器函数用于填充绘制的图形的颜色。

代码中还定义了绘制头部轮廓、头部、面部、胡须、嘴巴、鼻子、眼睛、眉毛、耳朵、帽子、阴影、身体、左手、右手、衣服、尾巴、鼓等各个部分的函数。每个函数使用turtle库的函数进行绘制,并使用装饰器函数添加填充颜色。

最后,在主函数中设置了窗口的大小和背景颜色,并依次调用各个绘制函数绘制出完整的小老虎图形。

🎃实现效果:


 🎯turtle动态小老虎:

🎃代码功能:

绘制乌龟的图形的功能。具体功能如下:

  1. 绘制乌龟的鼻子。
  2. 绘制乌龟的头部。
  3. 绘制乌龟的耳朵。
  4. 绘制乌龟的眼睛。
  5. 绘制乌龟的腮。
  6. 绘制乌龟的嘴巴。
  7. 绘制乌龟的身体。
  8. 绘制乌龟的手。
  9. 绘制乌龟的脚。
  10. 绘制乌龟的尾巴。

通过调用 main() 函数,可以将所有的部分组合在一起,绘制出完整的乌龟图形。

🎃分布解析该代码:

导入 turtle 库

from turtle import*

这一部分代码实现的是小猪佩奇的鼻子和鼻孔,由两个圆圈组成。 

def nose(x,y):#鼻子penup()goto(x,y)pendown()setheading(-30)begin_fill()a=0.4for i in range(120):if 0<=i<30 or 60<=i<90:a=a+0.08left(3)forward(a)else:a=a-0.08left(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)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.4for i in range(60):if 0<=i<30 or 60<=i<90:a=a+0.08lt(3)fd(a)else:a=a-0.08lt(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)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()

🎃实现代码:

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

🎃 实现效果:

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/618299.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

AR HUD全面「上新」

AR HUD赛道正在迎来新的时代。 上周&#xff0c;蔚来ET9正式发布亮相&#xff0c;新车定位为D级行政旗舰轿车&#xff0c;其中&#xff0c;在智能座舱交互层面&#xff0c;继理想L系列、长安深蓝S7之后&#xff0c;也首次取消仪表盘&#xff0c;取而代之的是业内首个全焦段AR H…

分块矩阵的定义、计算

目录 一、定义 二、分块矩阵的加减乘法 三、考点 一、定义 分块&#xff0c;顾名思义&#xff0c;将整个矩阵分成几部分&#xff0c;如下图所示 二、分块矩阵的加减乘法 三、考点 分块矩阵的考点不多&#xff0c;一般来说&#xff0c;有一种&#xff1a; 求分块矩阵的转置…

PHP如何拆分中文名字(包括少数民族名字)

/*** param string|null $name* return array|null*/ function splitName($name) {if (empty($name) || empty(trim($name))) {return null;}//该正则是用来提取$name参数里面的中文字符的。preg_match_all(/[\x{4e00}-\x{9fff}]/u, $name, $matchers);$matchersCount isset($…

2024年,谷歌云首席技术官眼中的生成AI三大支柱,来看看有啥新花样

每周跟踪AI热点新闻动向和震撼发展 想要探索生成式人工智能的前沿进展吗&#xff1f;订阅我们的简报&#xff0c;深入解析最新的技术突破、实际应用案例和未来的趋势。与全球数同行一同&#xff0c;从行业内部的深度分析和实用指南中受益。不要错过这个机会&#xff0c;成为AI领…

App在线封装的革命性创新

随着移动互联网的蓬勃发展&#xff0c;App已经成为我们日常生活中不可或缺的一部分。从购物、交通、社交到娱乐&#xff0c;几乎每个人的智能手机都装载着数十个应用程序&#xff0c;以满足各式各样的需求。然而&#xff0c;对于许多非技术背景的企业家和小型企业而言&#xff…

【机器学习】模型参数优化工具:Optuna使用分步指南(附XGB/LGBM调优代码)

常用的调参方式和工具包 常用的调参方式包括网格搜索(Grid Search)、**随机搜索(Random Search)和贝叶斯优化(Bayesian Optimization)**等。 工具包方面&#xff0c;Scikit-learn提供了GridSearchCV和RandomizedSearchCV等用于网格搜索和随机搜索的工具。另外&#xff0c;有一…

VS报错:error:LNK2005 _main 已经在 *.obj 中定义

应该是重定义了&#xff0c;但是又解决不了&#xff0c;看似又没有重定义啊&#xff0c;就在一个文件定义了啊&#xff1f;怎么会出现这种情况呢&#xff1f;关键是&#xff0c;编译报错&#xff0c;程序运行不了了。 这里提一下我的前期操作&#xff0c;是因为将一个头文件和…

NULL是什么?

NULL是一个编程术语&#xff0c;通常用于表示一个空值或无效值。在很多编程语言中&#xff0c;NULL用于表示一个变量或指针不引用任何有效的对象或内存位置。 NULL可以看作是一个特殊的值&#xff0c;表示缺少有效的数据或引用。当一个变量被赋予NULL值时&#xff0c;它表示该变…

【面试宝典】图解ARP协议、TCP协议、UDP协议

一、ARP协议 二、TCP协议 三、UDP协议 四、TCP和UDP的区别

如何有效使用360评估

导语&#xff1a;360度评估是绩效考核方法之一&#xff0c;被评估者不仅可以从自己、上司、部属、甚至顾客处获得多种角度的反馈&#xff0c;也可从这些不同的反馈清楚地认识到自己的不足、长处与发展需求。但360度评估也有其适用的范围和条件&#xff0c;华为总裁任正非给出了…

impala元数据自动刷新

一.操作步骤 进入CM界面 > Hive > 配置 > 搜索 启用数据库中的存储通知(英文界面搜索&#xff1a;Enable Stored Notifications in Database)&#xff0c;并且勾选&#xff0c;注意一定要勾选&#xff0c;配置后面的配置不生效。数据库通知的保留时间默认为2天&#…

Nacos下载与安装【windows】

&#x1f95a;今日鸡汤&#x1f95a; 我不知将去何方&#xff0c;但我已经在路上。 ——宫崎骏《千与千寻》 目录 &#x1f95e;1.Nacosdi地址 &#x1f32d;2.GitHub下载 &#x1f37f;3.目录结构 &#x1f953;4.启动nacos &#x1f9c2;5.客户端登陆 &#x1f9c8…

GitHub 一周热点汇总第5期(2024/01/07-01/13)

GitHub一周热点汇总第5期 (2024/01/07-01/13)&#xff0c;梳理每周热门的GitHub项目&#xff0c;这一周的热门项目都普遍比较年轻&#xff0c;有几个更是刚刚发布就火热起来了&#xff0c;一起来看看都有哪些项目吧。 #1 llm-course 项目名称&#xff1a;llm-course - 大语言…

华为路由器OSPF动态链路路由协议配置

R1配置 interface GigabitEthernet0/0/0ip address 10.1.12.1 255.255.255.252 interface LoopBack0ip address 1.1.1.1 255.255.255.255 ospf 1 router-id 1.1.1.1 area 0.0.0.0 network 1.1.1.1 0.0.0.0 network 10.1.12.0 0.0.0.3 R2配置 interface GigabitEthernet0/0/0i…

特征工程-特征处理(一)

特征处理-&#xff08;离散型特征处理&#xff09; 完成特征理解和特征清洗之后&#xff0c;我们要进行特征工程中最为重要和复杂的一步了——特征处理 离散型特征处理 离散型特征通常为非连续值或以字符串形式存在的特征&#xff0c;离散型特征通常来讲是不能直接喂入模型中…

四川云汇优想教育咨询有限公司引领电商未来

四川云汇优想教育咨询有限公司&#xff0c;一家在电商服务领域崭露头角的领军企业&#xff0c;致力于为广大客户提供最优质、最全面的电商服务。作为业界翘楚&#xff0c;云汇优想凭借其卓越的服务品质和强大的技术实力&#xff0c;在激烈的市场竞争中独树一帜&#xff0c;赢得…

将WAP网站封装成App体验的全新策略

一、传统的App封装方式 传统的App封装技术通常依赖于WebView组件&#xff0c;将WAP内容嵌入到一个原生App框架中。这种方法虽然可以快速实现WAP到App的转换&#xff0c;但存在着明显的缺陷&#xff1a;首先&#xff0c;WebView的性能和用户体验都无法与原生组件相提并论&#x…

金蝶云星空与金蝶云星空对接集成逐个单据查询连通员工新增(3009-销售退货清理卡片)

金蝶云星空与金蝶云星空对接集成逐个单据查询连通员工新增(3009-销售退货清理卡片) 来源系统:金蝶云星空 金蝶K/3Cloud&#xff08;金蝶云星空&#xff09;是移动互联网时代的新型ERP&#xff0c;是基于WEB2.0与云技术的新时代企业管理服务平台。金蝶K/3Cloud围绕着“生态、人人…

【TC3xx芯片】TC3xx芯片电源管理系统PMS详解

目录 前言 正文 1.供电模式选择&#xff08;Supply Mode Selection&#xff09; 1.1 供电域 1.2 供电模式 1.3 供电阈值 1.4 供电上升和下降行为Supply Ramp-up and Ramp-down Behavior 1.5 EVRC产生供电 2. 电源监控 2.1 电源监控原理 2.2 Primary低电压监控 2.3 …

C++六大组件之一:仿函数

场景一&#xff1a; 与其过多叙述定义&#xff0c;不如在下面一个场景中来理解仿函数&#xff1a; #include<iostream> using namespace std; template<class T> void bubbles_sort(T* arr,int size) //冒泡排序 {for (int i 0; i < size - 1; i){for (int j…