使用python的turtle库画kunkun
结果展示
完整代码
"""
任选主题绘制一幅作品,在图上的合适位置给出图名、学生姓名和学号(注:不是仅列出姓名和学号)。
提交代码和运行效果截图或录屏视频(jpg, png, mp4, gif等)
可读性好,看代码能够理解绘图过程和效果
采用基于帧的动画上限10分(不考虑海龟自身动画),否则上限为9分。
禁止学术不端行为。
"""
from turtle import *
import time
screensize(1000, 1000)
class PlowInformation(object):
"""显示个人信息"""
def __init__(self, turtle_obj, x=-550, y=400, arg=""):
"""
:param x: 信息横坐标位置
:param y: 信息纵坐标位置
:param arg: 显示的信息内容
"""
self.x = x
self.y = y
self.arg = arg
self.turtle_obj = turtle_obj # turtle的对象
self.turtle_obj.home() # 回到初始点和朝向,防止前面干扰
self.turtle_obj.speed(8)
def plow(self):
self.turtle_obj.penup()
self.turtle_obj.goto(self.x, self.y)
self.turtle_obj.write(self.arg, move=True, align='left', font=('微软雅黑', 15, 'normal'))
class PlowBasketball(object):
"""画篮球"""
def __init__(self, turtle_obj, circle_r=180, x=-300, y=-350, pen_size=5, spin_angle=210):
"""
:param circle_r: 画篮球的半径大小
:param x: 篮球底部的横坐标
:param y: 篮球底部的纵坐标
:param pen_size: 笔画大小
"""
self.x = x
self.y = y
self.circle_r = circle_r # 篮球半径
self.pen_size = pen_size
self.spin_angle = spin_angle
self.turtle_obj = turtle_obj # turtle的对象
self.turtle_obj.home() # 回到初始点和朝向,防止前面干扰
self.turtle_obj.speed(11)
def plow(self):
self.turtle_obj.penup()
self.turtle_obj.goto(self.x, self.y)
self.turtle_obj.down()
self.turtle_obj.pensize(self.pen_size)
self.turtle_obj.pencolor('black')
self.turtle_obj.fillcolor('chocolate')
self.turtle_obj.begin_fill() # 开始填充
self.turtle_obj.circle(self.circle_r, 360 + self.spin_angle) # 画圆,并且再转一定角度到左上角
self.turtle_obj.end_fill() # 结束填充
# 画第一个弧线
self.turtle_obj.left(90)
self.turtle_obj.circle(self.circle_r, 90)
# 顺时针转90度,画第二个弧线
self.turtle_obj.right(90)
self.turtle_obj.circle(-self.circle_r, 90)
self.turtle_obj.right(90)
self.turtle_obj.circle(self.circle_r, 90)
# 顺时针转45度,画中间的线
self.turtle_obj.right(90)
self.turtle_obj.circle(-self.circle_r, 45)
self.turtle_obj.right(90)
self.turtle_obj.fd(self.circle_r * 2)
self.turtle_obj.penup()
class PlowIkun(object):
"""画蔡徐坤"""
def __init__(self):
home() # 回到初始点和朝向,防止前面干扰
speed(8)
def plow_suspender_trousers(self):
"""背带裤"""
penup()
goto(-141, -179)
pensize(3)
fillcolor("black")
pencolor("black")
begin_fill()
pendown()
left(1)
forward(336)
circle(-20, 100)
right(30)
forward(22)
right(20)
setheading(-50) # 设置朝向
circle(-200, 50)
setheading(-180)
forward(420) # 最下面的横线
right(80)
circle(-200, 52)
left(90)
circle(-20, 150)
end_fill() # 填充黑色
"""背带裤白带,白带要大一点"""
# 画衣服里的线
pensize(35)
pencolor("white")
penup()
goto(-130, -214)
pendown()
seth(-45)
circle(-200, 50)
penup()
goto(200, -214)
pendown()
seth(230)
circle(200, 50)
penup()
def plow_head(self):
"""ikun头部"""
fillcolor("#ffe26c")
goto(-133, -183)
begin_fill()
pendown()
pencolor("black")
pensize(3)
seth(0)
forward(204)
right(25)
forward(40)
circle(60, 70)
circle(-70, 30)
left(20)
circle(150, 55)
seth(90)
forward(80)
penup()
"""右脸"""
goto(-133, -183)
pendown()
seth(150)
circle(-150, 60)
seth(90)
forward(50)
circle(-240.5, 171.4)
end_fill()
penup()
"""画五官,右边脸蛋"""
goto(-50, -86)
pencolor("red")
fillcolor("red")
begin_fill()
pendown()
seth(90)
circle(60, 360)
end_fill()
penup()
"""眼镜"""
goto(81, 32)
pendown()
pencolor("black")
fillcolor("white")
pensize(4)
begin_fill()
circle(70, 360)
end_fill()
begin_fill()
circle(-70, 360)
end_fill()
penup()
goto(59, 40)
pendown()
begin_fill()
fillcolor("black")
circle(10, 360)
end_fill()
penup()
goto(202, 40)
pendown()
begin_fill()
circle(10, 360)
end_fill()
penup()
"""画嘴巴"""
goto(21, -44)
fillcolor("#db8b68")
pencolor("#592404")
pensize(7)
begin_fill()
pendown()
seth(30)
circle(-120, 60)
circle(-44, 126)
circle(-120, 56)
circle(-42, 115)
end_fill()
penup()
goto(28, -85)
pendown()
seth(-32)
circle(110, 66)
penup()
"""左边脸蛋"""
goto(252, -42)
pendown()
pencolor("red")
fillcolor("red")
begin_fill()
seth(-76)
circle(-100, 50)
circle(-26, 130)
circle(-100, 46)
circle(-30, 120)
end_fill()
penup()
def plow_hair(self):
"""左侧头发"""
goto(265, 16)
pendown()
pencolor("#584e4f")
fillcolor("#6e676e")
begin_fill()
seth(51)
forward(56)
seth(90)
forward(75)
left(46)
forward(170)
left(28)
forward(130)
seth(180)
circle(50, 180)
right(10)
forward(30)
right(45)
forward(130)
seth(9.5)
circle(-100, 76)
end_fill()
penup()
"""右侧头发"""
goto(-208, -41)
pendown()
begin_fill()
seth(200)
forward(50)
right(99)
forward(133)
right(48)
forward(130)
right(12)
forward(100)
right(19)
forward(75)
seth(0)
forward(15)
circle(-42, 160)
seth(-91)
forward(150)
seth(170)
forward(50)
left(80)
forward(30)
right(50)
forward(50)
left(11)
forward(80)
end_fill()
penup()
def plow(self):
self.plow_suspender_trousers()
self.plow_head()
self.plow_hair()
PlowInformation_turtle_obj = Turtle() # 显示信息的turtle对象
PlowInformation_obj = PlowInformation(turtle_obj=PlowInformation_turtle_obj, x=-550, y=400,
arg="作品:KunKun喜欢篮球\n姓名:XXX\n学号:XXXXXXX")
PlowInformation_obj.plow()
PlowBasketball_turtle_obj = Turtle() # 显示篮球的turtle对象
PlowBasketball_obj = PlowBasketball(turtle_obj=PlowBasketball_turtle_obj, circle_r=200, x=-300, y=-380)
PlowBasketball_obj.plow()
PlowIkun_obj = PlowIkun()
PlowIkun_obj.plow()
tracer(False)
for i in range(100):
"""滚动的篮球"""
PlowBasketball_obj2_turtle_obj = Turtle()
PlowBasketball_obj2 = PlowBasketball(turtle_obj=PlowBasketball_obj2_turtle_obj, circle_r=i, x=400, y=500 - 10 * i,
spin_angle=i * 20)
PlowBasketball_obj2.plow()
update()
PlowBasketball_obj2.turtle_obj.hideturtle()
PlowBasketball_obj2.turtle_obj.clear()
time.sleep(0.01)
"""滚上滚下"""
"""向上"""
for j in range(70):
PlowBasketball_obj2_turtle_obj = Turtle()
PlowBasketball_obj2 = PlowBasketball(turtle_obj=PlowBasketball_obj2_turtle_obj, circle_r=99, x=400,
y=500 - 10 * 99 + 10 * j,
spin_angle=j * 20)
PlowBasketball_obj2.plow()
update()
PlowBasketball_obj2.turtle_obj.hideturtle()
PlowBasketball_obj2.turtle_obj.clear()
time.sleep(0.01)
while True:
"""最后定格在变大变小"""
for i in reversed(range(20, 99)):
PlowBasketball_obj2_turtle_obj = Turtle()
PlowBasketball_obj2 = PlowBasketball(turtle_obj=PlowBasketball_obj2_turtle_obj, circle_r=i, x=400,
y=500 - 10 * 99 + 10 * 69,
spin_angle=i * 20)
PlowBasketball_obj2.plow()
update()
PlowBasketball_obj2.turtle_obj.hideturtle()
PlowBasketball_obj2.turtle_obj.clear()
time.sleep(0.01)
for i in range(20, 99):
PlowBasketball_obj2_turtle_obj = Turtle()
PlowBasketball_obj2 = PlowBasketball(turtle_obj=PlowBasketball_obj2_turtle_obj, circle_r=i, x=400,
y=500 - 10 * 99 + 10 * 69,
spin_angle=i * 20)
PlowBasketball_obj2.plow()
update()
PlowBasketball_obj2.turtle_obj.hideturtle()
PlowBasketball_obj2.turtle_obj.clear()
time.sleep(0.01)
本文来自博客园,作者:JaxonYe,转载请注明原文链接:https://www.cnblogs.com/yechangxin/articles/17240310.html
侵权必究