Python绘制哆啦A梦、皮卡丘


Turtle库是Python语言中一个很流行的绘制图像的函数库,想象一个小乌龟,在一个横轴为x、纵轴为y的坐标系原点,(0,0)位置开始,它根据一组函数指令的控制,在这个平面坐标系中移动,从而在它爬行的路径上绘制了图形。

  • 官网:https://docs.python.org/zh-cn/3/library/turtle.html
  • https://github.com/PerpetualSmile

参考了网络代码,跟过turtle库用法可以参考turtle官网


turtle库绘制哆啦A梦

from turtle import *# 无轨迹跳跃
def my_goto(x, y):penup()goto(x, y)pendown()# 眼睛
def eyes():fillcolor("#ffffff")begin_fill()tracer(False)a = 2.5for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a -= 0.05lt(3)fd(a)else:a += 0.05lt(3)fd(a)tracer(True)end_fill()# 胡须
def beard():my_goto(-32, 135)seth(165)fd(60)my_goto(-32, 125)seth(180)fd(60)my_goto(-32, 115)seth(193)fd(60)my_goto(37, 135)seth(15)fd(60)my_goto(37, 125)seth(0)fd(60)my_goto(37, 115)seth(-13)fd(60)# 嘴巴
def mouth():my_goto(5, 148)seth(270)fd(100)seth(0)circle(120, 50)seth(230)circle(-120, 100)# 围巾
def scarf():fillcolor('#e70010')begin_fill()seth(0)fd(200)circle(-5, 90)fd(10)circle(-5, 90)fd(207)circle(-5, 90)fd(10)circle(-5, 90)end_fill()# 鼻子
def nose():my_goto(-10, 158)seth(315)fillcolor('#e70010')begin_fill()circle(20)end_fill()# 黑眼睛
def black_eyes():seth(0)my_goto(-20, 195)fillcolor('#000000')begin_fill()circle(13)end_fill()pensize(6)my_goto(20, 205)seth(75)circle(-10, 150)pensize(3)my_goto(-17, 200)seth(0)fillcolor('#ffffff')begin_fill()circle(5)end_fill()my_goto(0, 0)# 脸
def face():fd(183)lt(45)fillcolor('#ffffff')begin_fill()circle(120, 100)seth(180)# print(pos())fd(121)pendown()seth(215)circle(120, 100)end_fill()my_goto(63.56, 218.24)seth(90)eyes()seth(180)penup()fd(60)pendown()seth(90)eyes()penup()seth(180)fd(64)# 头型
def head():penup()circle(150, 40)pendown()fillcolor('#00a0de')begin_fill()circle(150, 280)end_fill()# 画哆啦A梦
def Doraemon():# 头部head()# 围脖scarf()# 脸face()# 红鼻子nose()# 嘴巴mouth()# 胡须beard()# 身体my_goto(0, 0)seth(0)penup()circle(150, 50)pendown()seth(30)fd(40)seth(70)circle(-30, 270)fillcolor('#00a0de')begin_fill()seth(230)fd(80)seth(90)circle(1000, 1)seth(-89)circle(-1000, 10)# print(pos())seth(180)fd(70)seth(90)circle(30, 180)seth(180)fd(70)# print(pos())seth(100)circle(-1000, 9)seth(-86)circle(1000, 2)seth(230)fd(40)# print(pos())circle(-30, 230)seth(45)fd(81)seth(0)fd(203)circle(5, 90)fd(10)circle(5, 90)fd(7)seth(40)circle(150, 10)seth(30)fd(40)end_fill()# 左手seth(70)fillcolor('#ffffff')begin_fill()circle(-30)end_fill()# 脚my_goto(103.74, -182.59)seth(0)fillcolor('#ffffff')begin_fill()fd(15)circle(-15, 180)fd(90)circle(-15, 180)fd(10)end_fill()my_goto(-96.26, -182.59)seth(180)fillcolor('#ffffff')begin_fill()fd(15)circle(15, 180)fd(90)circle(15, 180)fd(10)end_fill()# 右手my_goto(-133.97, -91.81)seth(50)fillcolor('#ffffff')begin_fill()circle(30)end_fill()# 口袋my_goto(-103.42, 15.09)seth(0)fd(38)seth(230)begin_fill()circle(90, 260)end_fill()my_goto(5, -40)seth(0)fd(70)seth(-90)circle(-70, 180)seth(0)fd(70)# 铃铛my_goto(-103.42, 15.09)fd(90)seth(70)fillcolor('#ffd200')# print(pos())begin_fill()circle(-20)end_fill()seth(170)fillcolor('#ffd200')begin_fill()circle(-2, 180)seth(10)circle(-100, 22)circle(-2, 180)seth(180 - 10)circle(100, 22)end_fill()goto(-13.42, 15.09)seth(250)circle(20, 110)seth(90)fd(15)dot(10)my_goto(0, -150)# 画眼睛black_eyes()if __name__ == '__main__':screensize(800, 600, "#f0f0f0")pensize(3)  # 画笔宽度speed(9)  # 画笔速度Doraemon()my_goto(100, -300)write('CSDN北山啦', font=("Bradley Hand ITC", 30, "bold"))mainloop()

turtle绘制皮卡丘


import turtledef getPosition(x, y):turtle.setx(x)turtle.sety(y)print(x, y)class Pikachu:def __init__(self):self.t = turtle.Turtle()t = self.tt.pensize(3)t.speed(9)t.ondrag(getPosition)def noTrace_goto(self, x, y):self.t.penup()self.t.goto(x, y)self.t.pendown()def leftEye(self, x, y):self.noTrace_goto(x, y)t = self.tt.seth(0)t.fillcolor('#333333')t.begin_fill()t.circle(22)t.end_fill()self.noTrace_goto(x, y+10)t.fillcolor('#000000')t.begin_fill()t.circle(10)t.end_fill()self.noTrace_goto(x+6, y + 22)t.fillcolor('#ffffff')t.begin_fill()t.circle(10)t.end_fill()def rightEye(self, x, y):self.noTrace_goto(x, y)t = self.tt.seth(0)t.fillcolor('#333333')t.begin_fill()t.circle(22)t.end_fill()self.noTrace_goto(x, y+10)t.fillcolor('#000000')t.begin_fill()t.circle(10)t.end_fill()self.noTrace_goto(x-6, y + 22)t.fillcolor('#ffffff')t.begin_fill()t.circle(10)t.end_fill()def mouth(self, x, y):self.noTrace_goto(x, y)t = self.tt.fillcolor('#88141D')t.begin_fill()# 下嘴唇l1 = []l2 = []t.seth(190)a = 0.7for i in range(28):a += 0.1t.right(3)t.fd(a)l1.append(t.position())self.noTrace_goto(x, y)t.seth(10)a = 0.7for i in range(28):a += 0.1t.left(3)t.fd(a)l2.append(t.position())# 上嘴唇t.seth(10)t.circle(50, 15)t.left(180)t.circle(-50, 15)t.circle(-50, 40)t.seth(233)t.circle(-50, 55)t.left(180)t.circle(50, 12.1)t.end_fill()# 舌头self.noTrace_goto(17, 54)t.fillcolor('#DD716F')t.begin_fill()t.seth(145)t.circle(40, 86)t.penup()for pos in reversed(l1[:20]):t.goto(pos[0], pos[1]+1.5)for pos in l2[:20]:t.goto(pos[0], pos[1]+1.5)t.pendown()t.end_fill()# 鼻子self.noTrace_goto(-17, 94)t.seth(8)t.fd(4)t.back(8)# 红脸颊def leftCheek(self, x, y):turtle.tracer(False)t = self.tself.noTrace_goto(x, y)t.seth(300)t.fillcolor('#DD4D28')t.begin_fill()a = 2.3for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a -= 0.05t.lt(3)t.fd(a)else:a += 0.05t.lt(3)t.fd(a)t.end_fill()turtle.tracer(True)def rightCheek(self, x, y):t = self.tturtle.tracer(False)self.noTrace_goto(x, y)t.seth(60)t.fillcolor('#DD4D28')t.begin_fill()a = 2.3for i in range(120):if 0 <= i < 30 or 60 <= i < 90:a -= 0.05t.lt(3)t.fd(a)else:a += 0.05t.lt(3)t.fd(a)t.end_fill()turtle.tracer(True)def colorLeftEar(self, x, y):t = self.tself.noTrace_goto(x, y)t.fillcolor('#000000')t.begin_fill()t.seth(330)t.circle(100, 35)t.seth(219)t.circle(-300, 19)t.seth(110)t.circle(-30, 50)t.circle(-300, 10)t.end_fill()def colorRightEar(self, x, y):t = self.tself.noTrace_goto(x, y)t.fillcolor('#000000')t.begin_fill()t.seth(300)t.circle(-100, 30)t.seth(35)t.circle(300, 15)t.circle(30, 50)t.seth(190)t.circle(300, 17)t.end_fill()def body(self):t = self.tt.fillcolor('#F6D02F')t.begin_fill()# 右脸轮廓t.penup()t.circle(130, 40)t.pendown()t.circle(100, 105)t.left(180)t.circle(-100, 5)# 右耳朵t.seth(20)t.circle(300, 30)t.circle(30, 50)t.seth(190)t.circle(300, 36)# 上轮廓t.seth(150)t.circle(150, 70)# 左耳朵t.seth(200)t.circle(300, 40)t.circle(30, 50)t.seth(20)t.circle(300, 35)#print(t.pos())# 左脸轮廓t.seth(240)t.circle(105, 95)t.left(180)t.circle(-105, 5)# 左手t.seth(210)t.circle(500, 18)t.seth(200)t.fd(10)t.seth(280)t.fd(7)t.seth(210)t.fd(10)t.seth(300)t.circle(10, 80)t.seth(220)t.fd(10)t.seth(300)t.circle(10, 80)t.seth(240)t.fd(12)t.seth(0)t.fd(13)t.seth(240)t.circle(10, 70)t.seth(10)t.circle(10, 70)t.seth(10)t.circle(300, 18)t.seth(75)t.circle(500, 8)t.left(180)t.circle(-500, 15)t.seth(250)t.circle(100, 65)# 左脚t.seth(320)t.circle(100, 5)t.left(180)t.circle(-100, 5)t.seth(220)t.circle(200, 20)t.circle(20, 70)t.seth(60)t.circle(-100, 20)t.left(180)t.circle(100, 20)t.seth(300)t.circle(10, 70)t.seth(60)t.circle(-100, 20)t.left(180)t.circle(100, 20)t.seth(10)t.circle(100, 60)# 横向t.seth(180)t.circle(-100, 10)t.left(180)t.circle(100, 10)t.seth(5)t.circle(100, 10)t.circle(-100, 40)t.circle(100, 35)t.left(180)t.circle(-100, 10)# 右脚t.seth(290)t.circle(100, 55)t.circle(10, 50)t.seth(120)t.circle(100, 20)t.left(180)t.circle(-100, 20)t.seth(0)t.circle(10, 50)t.seth(110)t.circle(100, 20)t.left(180)t.circle(-100, 20)t.seth(30)t.circle(20, 50)t.seth(100)t.circle(100, 40)# 右侧身体轮廓t.seth(200)t.circle(-100, 5)t.left(180)t.circle(100, 5)t.left(30)t.circle(100, 75)t.right(15)t.circle(-300, 21)t.left(180)t.circle(300, 3)# 右手t.seth(43)t.circle(200, 60)t.right(10)t.fd(10)t.circle(5, 160)t.seth(90)t.circle(5, 160)t.seth(90)t.fd(10)t.seth(90)t.circle(5, 180)t.fd(10)t.left(180)t.left(20)t.fd(10)t.circle(5, 170)t.fd(10)t.seth(240)t.circle(50, 30)t.end_fill()self.noTrace_goto(130, 125)t.seth(-20)t.fd(5)t.circle(-5, 160)t.fd(5)# 手指纹self.noTrace_goto(166, 130)t.seth(-90)t.fd(3)t.circle(-4, 180)t.fd(3)t.seth(-90)t.fd(3)t.circle(-4, 180)t.fd(3)# 尾巴self.noTrace_goto(168, 134)t.fillcolor('#F6D02F')t.begin_fill()t.seth(40)t.fd(200)t.seth(-80)t.fd(150)t.seth(210)t.fd(150)t.left(90)t.fd(100)t.right(95)t.fd(100)t.left(110)t.fd(70)t.right(110)t.fd(80)t.left(110)t.fd(30)t.right(110)t.fd(32)t.right(106)t.circle(100, 25)t.right(15)t.circle(-300, 2)###############print(t.pos())t.seth(30)t.fd(40)t.left(100)t.fd(70)t.right(100)t.fd(80)t.left(100)t.fd(46)t.seth(66)t.circle(200, 38)t.right(10)t.fd(10)t.end_fill()# 尾巴花纹 t.fillcolor('#923E24')self.noTrace_goto(126.82, -156.84)t.begin_fill()t.seth(30)t.fd(40)t.left(100)t.fd(40)t.pencolor('#923e24')t.seth(-30)t.fd(30)t.left(140)t.fd(20)t.right(150)t.fd(20)t.left(150)t.fd(20)t.right(150)t.fd(20)t.left(130)t.fd(18)t.pencolor('#000000')t.seth(-45)t.fd(67)t.right(110)t.fd(80)t.left(110)t.fd(30)t.right(110)t.fd(32)t.right(106)t.circle(100, 25)t.right(15)t.circle(-300, 2)t.end_fill()# 帽子、眼睛、嘴巴、脸颊self.cap(-134.07, 147.81)self.mouth(-5, 25)self.leftCheek(-126, 32)self.rightCheek(107, 63)self.colorLeftEar(-250, 100)self.colorRightEar(140, 270)self.leftEye(-85, 90)self.rightEye(50, 110)t.hideturtle()def cap(self, x, y):self.noTrace_goto(x, y)t = self.tt.fillcolor('#CD0000')t.begin_fill()t.seth(200)t.circle(400, 7)t.left(180)t.circle(-400, 30)t.circle(30, 60)t.fd(50)t.circle(30, 45)t.fd(60)t.left(5)t.circle(30, 70)t.right(20)t.circle(200, 70)t.circle(30, 60)t.fd(70)# print(t.pos())t.right(35)t.fd(50)t.circle(8, 100)t.end_fill()self.noTrace_goto(-168.47, 185.52)t.seth(36)t.circle(-270, 54)t.left(180)t.circle(270, 27)t.circle(-80, 98)t.fillcolor('#444444')t.begin_fill()t.left(180)t.circle(80, 197)t.left(58)t.circle(200, 45)t.end_fill()self.noTrace_goto(-58, 270)t.pencolor('#228B22')t.dot(35)self.noTrace_goto(-30, 280)t.fillcolor('#228B22')t.begin_fill()t.seth(100)t.circle(30, 180)t.seth(190)t.fd(15)t.seth(100)t.circle(-45, 180)t.right(90)t.fd(15)t.end_fill()t.pencolor('#000000')def start(self):self.body()def main():print('Painting the Pikachu... ')turtle.screensize(800, 600)turtle.title('Pikachu')pikachu = Pikachu()pikachu.start()turtle.mainloop()if __name__ == '__main__':main()

turtle绘制圣诞树

import turtlescreen = turtle.Screen()
screen.setup(800, 600)
circle = turtle.Turtle()
circle.shape('circle')
circle.color('red')
circle.speed('fastest')
circle.up()
square = turtle.Turtle()
square.shape('square')
square.color('green')
square.speed('fastest')
square.up()
circle.goto(0, 280)
circle.stamp()
k = 0
for i in range(1, 17):y = 30 * ifor j in range(i - k):x = 30 * jsquare.goto(x, -y + 280)square.stamp()square.goto(-x, -y + 280)square.stamp()if i % 4 == 0:x = 30 * (j + 1)circle.color('red')circle.goto(-x, -y + 280)circle.stamp()circle.goto(x, -y + 280)circle.stamp()k += 2if i % 4 == 3:x = 30 * (j + 1)circle.color('yellow')circle.goto(-x, -y + 280)circle.stamp()circle.goto(x, -y + 280)circle.stamp()
square.color('brown')
for i in range(17, 20):y = 30 * ifor j in range(3):x = 30 * jsquare.goto(x, -y + 280)square.stamp()square.goto(-x, -y + 280)square.stamp()
turtle.exitonclick()

到这里就结束了,如果对你有帮助,欢迎点赞关注,你的点赞对我很重要。作者:北山啦

Python绘制哆啦A梦、皮卡丘、圣诞树相关推荐

  1. python画图哆啦a梦-python 绘制哆啦A梦

    [实例简介] 绘制哆啦A梦 [实例截图] [核心代码] #!/usr/bin/python # -*- coding: UTF-8 -*- # 哆啦A梦 import turtle def flyTo ...

  2. 用python画多来a梦-python 绘制哆啦A梦

    [实例简介] 绘制哆啦A梦 [实例截图] [核心代码] #!/usr/bin/python # -*- coding: UTF-8 -*- # 哆啦A梦 import turtle def flyTo ...

  3. python绘制哆啦a梦实训报告_python画哆啦A梦和大雄

    最近从后台收到的消息来看,不少读者对 python 的 turtle 这个库感兴趣,也收到了读者想用 python 画各种图的各种需求.和一些读者沟通后才知道是学校布置了相关的作业,或者是自己想用这个 ...

  4. 【python】利用python的tkinter-canvas函数绘制哆啦A梦过程详解(附源码)

    1 引 言 绘制哆啦A梦的过程,其实是对哆啦A梦进行拆解的过程,得先构思出他的头部.眼睛.鼻子.嘴巴.胡须.身体.铃铛.口袋.手以及脚等(如下图所示),才能进行下一步的绘画工作.心中有丘壑,方能水到渠 ...

  5. python画图哆啦a梦-使用Python的Turtle绘制哆啦A梦实例

    这是我几年前为了练习python的turtle库而画的,今天翻出了代码,分享给大家. 这是我初学python时画的,当时还没有面向对象的概念,也没有采取类方法之类,纯原始手工,供大家参考. 若有兴趣可 ...

  6. 用python画多来a梦-使用Python的Turtle绘制哆啦A梦实例

    这是我几年前为了练习python的turtle库而画的,今天翻出了代码,分享给大家. 这是我初学python时画的,当时还没有面向对象的概念,也没有采取类方法之类,纯原始手工,供大家参考. 若有兴趣可 ...

  7. python编程100例海绵宝宝-用python画哆啦a梦

    广告关闭 2017年12月,云+社区对外发布,从最开始的技术博客到现在拥有多个社区产品.未来,我们一起乘风破浪,创造无限可能. 也收到了读者想用 python 画各种图的各种需求. 和一些读者沟通后才 ...

  8. python画图哆啦a梦-Python—turtle画图(哆啦A梦)

    [知识延伸] 在Python中有一个名为turtle的工具,也可以称他为画图工具,这是一种Python所独有的工具.是他为我们所包装好的模块,在这里 [要求] 今天我们利用turtle画图来绘制一个哆 ...

  9. python画图哆啦a梦大作业_Python—turtle画图(哆啦A梦)

    [知识延伸] 在Python中有一个名为turtle的工具,也可以称他为画图工具,这是一种Python所独有的工具.是他为我们所包装好的模块,在这里 [要求] 今天我们利用turtle画图来绘制一个哆 ...

最新文章

  1. 以下哪个选项不能减少用户计算机,2017年cad考试选择题「附答案」
  2. ICCV 2019 运行LCGN遇到的问题及解决办法
  3. 【若依(ruoyi)】数据选择对话框
  4. 37. Sudoku Solver
  5. 《R的极客理想—工具篇》—— 第2章 时间序列基础包
  6. android 屏幕管理软件,Android Screencast下载
  7. 力扣225-用队列实现栈(C++,附思路及优化思路,代码)
  8. CFS调度主要代码分析一
  9. lanswich交换机远程TELNET登录
  10. 华硕电脑重装系统后电池管理软件ASUS Battery Health Charging不见了
  11. visio一分二连接线_Visio-换线流程(初稿)
  12. 15个最佳电子商务Android应用模板
  13. 2010.5.7 MFC中弹对话框以跟踪和程序运行中修改Static Text的Caption属性
  14. 美团算法团队:深度学习在美团OCR中的应用!
  15. ListView优化机制及滑动时数据时出现的数据错乱重复问题 图片、checkBox等
  16. IP地址使用,分类等详解
  17. jQuery二维码生成
  18. TFB cas:223569-31-1,聚合物光电材料
  19. OpenWrt安装腾讯云DDNS插件
  20. 功能连接分析方法及其解释缺陷的综述

热门文章

  1. 讯飞语音识别和唤醒开发示例
  2. vue项目中自动跳转到外部链接
  3. 矩阵乘法基本概念及模板题目
  4. 【沃顿商学院学习笔记】商业分析——Customer Analytics:02 预测分析一:回归分析 Regression Analysis
  5. matlab rgb2gray的实现
  6. 360浏览器兼容模式css错乱问题
  7. 浏览器兼容模式下,上传文件问题
  8. 华中农大计算机排名,南京农业大学和华中农业大学哪个好啊,作为一个抱着在农业大学学计算机的想法的毕业党..有不有可爱的学长学姐给点意见...
  9. 中鑫吉鼎|24条理财常识让你越来越富
  10. Xamarin-移动端定位知识整理