作者:封亚飞 qq:64761294 题目来源于网络,代码自己写的
如果您有更好的方法,期待与您交流。
1.问题描述
使用turtle库绘制哔哩哔哩的小电视
2.问题分析
- 在平面直角坐标系中,对小电视进行简单的位置分析
- 找到特殊点位所在的坐标
- 模拟特殊曲线
3.设置基本参数
- 设置长度:200px
- 设置高度:160px
- 设置圆角半径:10px
- 设置眼镜角度和长度:30px,20°(左),160°(右)
- 设置天线角度和长度:50px,45°(左),135°(右)
- 设置嘴巴弧度和半径:(-10,180)(10,180)
- 设置足部弧度和半径:(-15,180)(15,180)
- 设置画笔颜色:#07B0F2
4.设计思想: 模块化
5.代码
`import turtle as t
#定义绘制轮廓模块
def lunkuo():
t.seth(0)
t.pu()
t.goto(0,80)
t.pd()
t.fd(100-10)
t.circle(10,90)
t.fd(2*(80-10))
t.circle(10,90)
t.fd(1002-20)
t.circle(10,90)
t.fd(2(80-10))
t.circle(10,90)
t.fd(100-10)
t.pu()
#定义绘制眼睛模块
def eyes():
t.seth(20)
t.goto(-50,20+160)
t.pd()
t.fd(30)
t.pu()
t.seth(160)
t.goto(50,20+160)
t.pd()
t.fd(30)
t.pu()
#定义绘制耳朵模块
def erduo():
t.seth(45)
t.goto(30,240)
t.pd()
t.fd(50)
t.pu()
t.seth(135)
t.goto(-30,240)
t.pd()
t.fd(50)
t.pu()
#定义绘制嘴巴模块
def mouth():
t.pensize(5)
t.goto(0,130)
t.pd()
t.seth(-90)
t.circle(-10,180)
t.pu()
t.goto(0,130)
t.seth(-90)
t.pd()
t.circle(10,180)
t.pu()
#定义绘制脚模块
def foot():
t.pensize(8)
t.goto(-45,80)
t.seth(-90)
t.pd()
t.begin_fill()
t.circle(-15,180)
t.end_fill()
t.pu()
t.goto(45,80)
t.seth(-90)
t.pd()
t.begin_fill()
t.circle(15,180)
t.end_fill()
t.pu()
#定义绘制图形主函数main_png()
def main_png():
t.hideturtle()
t.pensize(10)
t.color(’#07B0F2’)
lunkuo()
eyes()
erduo()
mouth()
foot()
#开始绘制图形
main_png()
#定义写字模块
def wenzi():
t.pu()
t.goto(-80,0)
t.pd()
t.write(“bilibili”,font = (“C:\Windows\Fonts\Swis721 Lt BT.ttf”, 30,“bold”))
#执行写字
wenzi()
t.done()
`
6.效果图