使用Python的Turtle绘制哆啦A梦实例


Posted in Python onNovember 21, 2019

这是我几年前为了练习python的turtle库而画的,今天翻出了代码,分享给大家。

这是我初学python时画的,当时还没有面向对象的概念,也没有采取类方法之类,纯原始手工,供大家参考。

若有兴趣可以自行优化简洁代码,有时间我也会重新写一遍。

画出来的效果如下图:

使用Python的Turtle绘制哆啦A梦实例

代码如下:

# * -- utf-8 -- *
# Author: Tang
 
import turtle as t
 
t.speed(10)
t.pensize(8)
t.hideturtle()
t.screensize(500, 500, bg='white')
 
# 猫脸
t.fillcolor('#00A1E8')
t.begin_fill()
t.circle(120)
t.end_fill()
 
t.pensize(3)
t.fillcolor('white')
t.begin_fill()
t.circle(100)
t.end_fill()
 
t.pu()
t.home()
t.goto(0, 134)
t.pd()
t.pensize(4)
t.fillcolor("#EA0014")
t.begin_fill()
t.circle(18)
t.end_fill()
 
t.pu()
t.goto(7, 155)
t.pensize(2)
t.color('white', 'white')
t.pd()
t.begin_fill()
t.circle(4)
t.end_fill()
 
t.pu()
t.goto(-30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
a = 0.4
for i in range(120):
  if 0 <= i < 30 or 60 <= i < 90:
    a = a+0.08
    t.lt(3) #向左转3度
    t.fd(a) #向前走a的步长
  else:
    a = a-0.08
    t.lt(3)
    t.fd(a)
t.end_fill()
 
t.pu()
t.goto(30, 160)
t.pensize(4)
t.pd()
t.color('black', 'white')
t.begin_fill()
for i in range(120):
  if 0 <= i < 30 or 60 <= i < 90:
    a = a+0.08
    t.lt(3) # 向左转3度
    t.fd(a) # 向前走a的步长
  else:
    a = a-0.08
    t.lt(3)
    t.fd(a)
t.end_fill()
 
t.pu()
t.goto(-38,190)
t.pensize(8)
t.pd()
t.right(-30)
t.forward(15)
t.right(70)
t.forward(15)
 
t.pu()
t.goto(15, 185)
t.pensize(4)
t.pd()
t.color('black', 'black')
t.begin_fill()
t.circle(13)
t.end_fill()
 
t.pu()
t.goto(13, 190)
t.pensize(2)
t.pd()
t.color('white', 'white')
t.begin_fill()
t.circle(5)
t.end_fill()
 
t.pu()
t.home()
t.goto(0, 134)
t.pensize(4)
t.pencolor('black')
t.pd()
t.right(90)
t.forward(40)
 
t.pu()
t.home()
t.goto(0, 124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(10)
t.forward(80)
 
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(6)
t.forward(80)
 
t.pu()
t.home()
t.goto(0,104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(0)
t.forward(80)
 
# 左边的胡子
t.pu()
t.home()
t.goto(0,124)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(170)
t.forward(80)
 
t.pu()
t.home()
t.goto(0, 114)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(174)
t.forward(80)
 
t.pu()
t.home()
t.goto(0, 104)
t.pensize(3)
t.pencolor('black')
t.pd()
t.left(180)
t.forward(80)
 
t.pu()
t.goto(-70, 70)
t.pd()
t.color('black', 'red')
t.pensize(6)
t.seth(-60)
t.begin_fill()
t.circle(80,40)
t.circle(80,80)
t.end_fill()
 
t.pu()
t.home()
t.goto(-80,70)
t.pd()
t.forward(160)
 
t.pu()
t.home()
t.goto(-50,50)
t.pd()
t.pensize(1)
t.fillcolor("#eb6e1a")
t.seth(40)
t.begin_fill()
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(40)
t.circle(-40, 40)
t.circle(-40, 40)
t.seth(220)
t.circle(-80, 40)
t.circle(-80, 40)
t.end_fill()
 
# 领带
t.pu()
t.goto(-70, 12)
t.pensize(14)
t.pencolor('red')
t.pd()
t.seth(-20)
t.circle(200, 30)
t.circle(200, 10)
 
# 铃铛
t.pu()
t.goto(0, -46)
t.pd()
t.pensize(3)
t.color("black", '#f8d102')
t.begin_fill()
t.circle(25)
t.end_fill()
 
 
t.pu()
t.goto(-5, -40)
t.pd()
t.pensize(2)
t.color("black", '#79675d')
t.begin_fill()
t.circle(5)
t.end_fill()
 
t.pensize(3)
t.right(115)
t.forward(7)
 
t.mainloop()

以上这篇使用Python的Turtle绘制哆啦A梦实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持三水点靠木。

Python 相关文章推荐
Python中类的继承代码实例
Oct 28 Python
Python Web框架Flask信号机制(signals)介绍
Jan 01 Python
Python中Class类用法实例分析
Nov 12 Python
关于django 数据库迁移(migrate)应该知道的一些事
May 27 Python
Python中按值来获取指定的键
Mar 04 Python
Windows+Anaconda3+PyTorch+PyCharm的安装教程图文详解
Apr 03 Python
详解python变量与数据类型
Aug 25 Python
Python虚拟环境的创建和使用详解
Sep 07 Python
Python利用matplotlib绘制折线图的新手教程
Nov 05 Python
python中用ctypes模拟点击的实例讲解
Nov 26 Python
django中cookiecutter的使用教程
Dec 03 Python
PyQt QMainWindow的使用示例
Mar 24 Python
Python 类的魔法属性用法实例分析
Nov 21 #Python
python画蝴蝶曲线图的实例
Nov 21 #Python
Python 静态方法和类方法实例分析
Nov 21 #Python
Python 用turtle实现用正方形画圆的例子
Nov 21 #Python
python 实现兔子生兔子示例
Nov 21 #Python
python3实现用turtle模块画一棵随机樱花树
Nov 21 #Python
用python中的matplotlib绘制方程图像代码
Nov 21 #Python
You might like
php中的时间处理
2006/10/09 PHP
非常全面的php日期时间运算汇总
2015/11/04 PHP
PHP模板引擎Smarty内建函数详解
2016/04/11 PHP
PHP实现的贪婪算法实例
2017/10/17 PHP
php实现的AES加密类定义与用法示例
2018/01/29 PHP
PDO::getAvailableDrivers讲解
2019/01/28 PHP
在Laravel中使用MongoDB的方法示例
2019/11/11 PHP
jQuery each()方法的使用方法
2010/03/18 Javascript
JSON传递bool类型数据的处理方式介绍
2013/09/18 Javascript
Bootstrap风格的WPF样式
2016/12/07 Javascript
详解AngularJS ui-sref的简单使用
2017/04/24 Javascript
AngularJS实现图片上传和预览功能的方法分析
2017/11/08 Javascript
Angular数据绑定机制原理
2018/04/17 Javascript
layui获取多选框中的值方法
2018/08/15 Javascript
原来JS还可以这样拆箱转换详解
2019/02/01 Javascript
vue.js的简单自动求和计算实例
2019/11/08 Javascript
JavaScript使用百度ECharts插件绘制饼图操作示例
2019/11/26 Javascript
antd table按表格里的日期去排序操作
2020/11/17 Javascript
Python入门篇之文件
2014/10/20 Python
Perl中著名的Schwartzian转换问题解决实现
2015/06/02 Python
Python遍历文件夹和读写文件的实现方法
2017/05/10 Python
python僵尸进程产生的原因
2017/07/21 Python
详解Django中类视图使用装饰器的方式
2018/08/12 Python
Python进阶之@property动态属性的实现
2019/04/01 Python
PyTorch: 梯度下降及反向传播的实例详解
2019/08/20 Python
Python中字典与恒等运算符的用法分析
2019/08/22 Python
Python with关键字,上下文管理器,@contextmanager文件操作示例
2019/10/17 Python
小结Python的反射机制
2020/09/28 Python
CSS3 transform的skew属性值图文详解
2014/07/21 HTML / CSS
OSPREY LONDON官网:英国本土皮具品牌
2019/05/31 全球购物
收银员岗位职责
2015/02/03 职场文书
民主评议党员个人总结
2015/02/13 职场文书
2015年度优秀员工自荐书
2015/03/06 职场文书
女性健康知识讲座通知
2015/04/23 职场文书
2019请假条的基本格式及范文!
2019/07/05 职场文书
AndroidStudio图片压缩工具ImgCompressPlugin使用实例
2022/08/05 Java/Android