用Python+turtle绘制佩琪:

  1. from turtle import *
  2.  
  3. def nose(x,y):#鼻子
  4. penup()#提起笔
  5. goto(x,y)#定位
  6. pendown()#落笔,开始画
  7. setheading(-30)#将乌龟的方向设置为to_angle/为数字(0-东、90-北、180-西、270-南)
  8. begin_fill()#准备开始填充图形
  9. a=0.4
  10. for i in range(120):
  11. if 0<=i<30 or 60<=i<90:
  12. a=a+0.08
  13. left(3) #向左转3度
  14. forward(a) #向前走a的步长
  15. else:
  16. a=a-0.08
  17. left(3)
  18. forward(a)
  19. end_fill()#填充完成
  20.  
  21. penup()
  22. setheading(90)
  23. forward(25)
  24. setheading(0)
  25. forward(10)
  26. pendown()
  27. pencolor(255,155,192)#画笔颜色
  28. setheading(10)
  29. begin_fill()
  30. circle(5)
  31. color(160,82,45)#返回或设置pencolorfillcolor
  32. end_fill()
  33.  
  34. penup()
  35. setheading(0)
  36. forward(20)
  37. pendown()
  38. pencolor(255,155,192)
  39. setheading(10)
  40. begin_fill()
  41. circle(5)
  42. color(160,82,45)
  43. end_fill()
  44.  
  45. def head(x,y):#头
  46. color((255,155,192),"pink")
  47. penup()
  48. goto(x,y)
  49. setheading(0)
  50. pendown()
  51. begin_fill()
  52. setheading(180)
  53. circle(300,-30)
  54. circle(100,-60)
  55. circle(80,-100)
  56. circle(150,-20)
  57. circle(60,-95)
  58. setheading(161)
  59. circle(-300,15)
  60. penup()
  61. goto(-100,100)
  62. pendown()
  63. setheading(-30)
  64. a=0.4
  65. for i in range(60):
  66. if 0<=i<30 or 60<=i<90:
  67. a=a+0.08
  68. lt(3) #向左转3度
  69. fd(a) #向前走a的步长
  70. else:
  71. a=a-0.08
  72. lt(3)
  73. fd(a)
  74. end_fill()
  75.  
  76. def ears(x,y): #耳朵
  77. color((255,155,192),"pink")
  78. penup()
  79. goto(x,y)
  80. pendown()
  81. begin_fill()
  82. setheading(100)
  83. circle(-50,50)
  84. circle(-10,120)
  85. circle(-50,54)
  86. end_fill()
  87.  
  88. penup()
  89. setheading(90)
  90. forward(-12)
  91. setheading(0)
  92. forward(30)
  93. pendown()
  94. begin_fill()
  95. setheading(100)
  96. circle(-50,50)
  97. circle(-10,120)
  98. circle(-50,56)
  99. end_fill()
  100.  
  101. def eyes(x,y):#眼睛
  102. color((255,155,192),"white")
  103. penup()
  104. setheading(90)
  105. forward(-20)
  106. setheading(0)
  107. forward(-95)
  108. pendown()
  109. begin_fill()
  110. circle(15)
  111. end_fill()
  112.  
  113. color("black")
  114. penup()
  115. setheading(90)
  116. forward(12)
  117. setheading(0)
  118. forward(-3)
  119. pendown()
  120. begin_fill()
  121. circle(3)
  122. end_fill()
  123.  
  124. color((255,155,192),"white")
  125. penup()
  126. seth(90)
  127. forward(-25)
  128. seth(0)
  129. forward(40)
  130. pendown()
  131. begin_fill()
  132. circle(15)
  133. end_fill()
  134.  
  135. color("black")
  136. penup()
  137. setheading(90)
  138. forward(12)
  139. setheading(0)
  140. forward(-3)
  141. pendown()
  142. begin_fill()
  143. circle(3)
  144. end_fill()
  145.  
  146. def cheek(x,y):#腮
  147. color((255,155,192))
  148. penup()
  149. goto(x,y)
  150. pendown()
  151. setheading(0)
  152. begin_fill()
  153. circle(30)
  154. end_fill()
  155.  
  156. def mouth(x,y): #嘴
  157. color(239,69,19)
  158. penup()
  159. goto(x,y)
  160. pendown()
  161. setheading(-80)
  162. circle(30,40)
  163. circle(40,80)
  164.  
  165. def body(x,y):#身体
  166. color("red",(255,99,71))
  167. penup()
  168. goto(x,y)
  169. pendown()
  170. begin_fill()
  171. setheading(-130)
  172. circle(100,10)
  173. circle(300,30)
  174. setheading(0)
  175. forward(230)
  176. setheading(90)
  177. circle(300,30)
  178. circle(100,3)
  179. color((255,155,192),(255,100,100))
  180. setheading(-135)
  181. circle(-80,63)
  182. circle(-150,24)
  183. end_fill()
  184.  
  185. def hands(x,y):#手
  186. color((255,155,192))
  187. penup()
  188. goto(x,y)
  189. pendown()
  190. setheading(-160)
  191. circle(300,15)
  192. penup()
  193. setheading(90)
  194. forward(15)
  195. setheading(0)
  196. forward(0)
  197. pendown()
  198. setheading(-10)
  199. circle(-20,90)
  200.  
  201. penup()
  202. setheading(90)
  203. forward(30)
  204. setheading(0)
  205. forward(237)
  206. pendown()
  207. setheading(-20)
  208. circle(-300,15)
  209. penup()
  210. setheading(90)
  211. forward(20)
  212. setheading(0)
  213. forward(0)
  214. pendown()
  215. setheading(-170)
  216. circle(20,90)
  217.  
  218. def foot(x,y):#脚
  219. pensize(10)
  220. color((240,128,128))
  221. penup()
  222. goto(x,y)
  223. pendown()
  224. setheading(-90)
  225. forward(40)
  226. setheading(-180)
  227. color("black")
  228. pensize(15)
  229. fd(20)
  230.  
  231. pensize(10)
  232. color((240,128,128))
  233. penup()
  234. setheading(90)
  235. forward(40)
  236. setheading(0)
  237. forward(90)
  238. pendown()
  239. setheading(-90)
  240. forward(40)
  241. setheading(-180)
  242. color("black")
  243. pensize(15)
  244. fd(20)
  245.  
  246. def tail(x,y):#尾巴
  247. pensize(4)
  248. color((255,155,192))
  249. penup()
  250. goto(x,y)
  251. pendown()
  252. seth(0)
  253. circle(70,20)
  254. circle(10,330)
  255. circle(70,30)
  256.  
  257. def setting(): #参数设置
  258. pensize(4)
  259. hideturtle() #使乌龟无形(隐藏)
  260. colormode(255) #将其设置为1.0或255.随后 颜色三元组的r,g,b值必须在0 .. cmode范围内
  261. color((255,155,192),"pink")
  262. setup(840,500)
  263. speed(10)
  264.  
  265. def main():
  266. setting() #画布、画笔设置
  267. nose(-100,100) #鼻子
  268. head(-69,167) #头
  269. ears(0,160) #耳朵
  270. eyes(0,140) #眼睛
  271. cheek(80,10) #腮
  272. mouth(-20,30) #嘴
  273. body(-32,-8) #身体
  274. hands(-56,-45) #手
  275. foot(2,-177) #脚
  276. tail(148,-155) #尾巴
  277. done()
  278.  
  279. if __name__ == '__main__':
  280. main()

用Python+turtle库绘制动画重现龟兔赛跑现场:

  1. import numpy as np
  2. import matplotlib.pyplot as plt
  3. import matplotlib.font_manager as fm
  4.  
  5. t=np.arange(0,120,0.5)
  6. rabbit=np.piecewise(t,
  7. [t<10,t>110],
  8. [lambda x:15*x,
  9. lambda x:20*(x-110)+150,
  10. lambda x:150]
  11. )
  12. tortoise=3*t
  13. plt.plot(t,tortoise,label='乌龟')
  14. plt.plot(t,rabbit,label='兔子')
  15. plt.title('龟兔赛跑',fontpropertise='STKAITI',fontsize=24)
  16. plt.xlabel('时间(秒)',fontpropertise='STKAITI',fontsize=18)
  17. plt.ylabel('与起点的距离(米)',fontpropertise='simbei',fontsize=18)
  18. plt.show()

绘制交互式绘图小海龟:

绘制玫瑰花

  1. from turtle import *
  2. #global pen and speed
  3. pencolor("black")
  4. fillcolor("red")
  5. speed(50)
  6. s=0.15
  7. #init poistion
  8. penup()
  9. goto(0,600*s)
  10. pendown()
  11. begin_fill()
  12. circle(200*s,30)
  13. for i in range(60):
  14. lt(1)
  15. circle(50*s,1)
  16. circle(200*s,30)
  17. for i in range(4):
  18. lt(1)
  19. circle(100*s,1)
  20. circle(200*s,50)
  21. for i in range(50):
  22. lt(1)
  23. circle(50*s,1)
  24. circle(350*s,65)
  25. for i in range(40):
  26. lt(1)
  27. circle(70*s,1)
  28. circle(150*s,50)
  29. for i in range(20):
  30. rt(1)
  31. circle(50*s,1)
  32. circle(400*s,60)
  33. for i in range(18):
  34. lt(1)
  35. circle(50*s,1)
  36. fd(250*s)
  37. rt(150)
  38. circle(-500*s,12)
  39. lt(140)
  40. circle(550*s,110)
  41. lt(27)
  42. circle(650*s,100)
  43. lt(130)
  44. circle(-300*s,20)
  45. rt(123)
  46. circle(220*s,57)
  47. end_fill()
  48. lt(120)
  49. fd(280*s)
  50. lt(115)
  51. circle(300*s,33)
  52. lt(180)
  53. circle(-300*s,33)
  54. for i in range(70):
  55. rt(1)
  56. circle(225*s,1)
  57. circle(350*s,104)
  58. lt(90)
  59. circle(200*s,105)
  60. circle(-500*s,63)
  61. penup()
  62. goto(170*s,-330*s)
  63. pendown()
  64. lt(160)
  65. for i in range(20):
  66. lt(1)
  67. circle(2500*s,1)
  68. for i in range(220):
  69. rt(1)
  70. circle(250*s,1)
  71. fillcolor('green')
  72. penup()
  73. goto(670*s,-480*s)
  74. pendown()
  75. rt(140)
  76. begin_fill()
  77. circle(300*s,120)
  78. lt(60)
  79. circle(300*s,120)
  80. end_fill()
  81. penup()
  82. goto(180*s,-850*s)
  83. pendown()
  84. rt(85)
  85. circle(600*s,40)
  86. penup()
  87. goto(-150*s,-1300*s)
  88. pendown()
  89. begin_fill()
  90. rt(120)
  91. circle(300*s,115)
  92. lt(75)
  93. circle(300*s,100)
  94. end_fill()
  95. penup()
  96. goto(430*s,-1370*s)
  97. pendown()
  98. rt(30)
  99. circle(-600*s,35)
  100. done()

画太阳花:

  1. from turtle import *
  2. color('red','yellow')
  3. begin_fill()
  4. while True:
  5. forward(200)
  6. left(170)
  7. if abs(pos())<1:
  8. break
  9. end_fill()
  10. done()

python+turtle 笔记的更多相关文章

  1. python turtle笔记

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

  2. Web Scraping with Python读书笔记及思考

    Web Scraping with Python读书笔记 标签(空格分隔): web scraping ,python 做数据抓取一定一定要明确:抓取\解析数据不是目的,目的是对数据的利用 一般的数据 ...

  3. python学习笔记整理——字典

    python学习笔记整理 数据结构--字典 无序的 {键:值} 对集合 用于查询的方法 len(d) Return the number of items in the dictionary d. 返 ...

  4. VS2013中Python学习笔记[Django Web的第一个网页]

    前言 前面我简单介绍了Python的Hello World.看到有人问我搞搞Python的Web,一时兴起,就来试试看. 第一篇 VS2013中Python学习笔记[环境搭建] 简单介绍Python环 ...

  5. python学习笔记之module && package

    个人总结: import module,module就是文件名,导入那个python文件 import package,package就是一个文件夹,导入的文件夹下有一个__init__.py的文件, ...

  6. python datetime笔记

    python datetime笔记 http://mint-green.diandian.com/post/2011-09-09/4892024 获取当前时间,并通过字符串输出. 格式为:%Y-%m- ...

  7. python学习笔记(六)文件夹遍历,异常处理

    python学习笔记(六) 文件夹遍历 1.递归遍历 import os allfile = [] def dirList(path): filelist = os.listdir(path) for ...

  8. python学习笔记--Django入门四 管理站点--二

    接上一节  python学习笔记--Django入门四 管理站点 设置字段可选 编辑Book模块在email字段上加上blank=True,指定email字段为可选,代码如下: class Autho ...

  9. python学习笔记--Django入门0 安装dangjo

    经过这几天的折腾,经历了Django的各种报错,翻译的内容虽然不错,但是与实际的版本有差别,会出现各种奇葩的错误.现在终于找到了解决方法:查看英文原版内容:http://djangobook.com/ ...

随机推荐

  1. Linux查杀stopped进程

      在Linux系统下面,top命令可以查看查看stopped进程.但是不能查看stopped进程的详细信息.那么如何查看stopped 进程,并且杀掉这些stopped进程呢? ps -e j | ...

  2. varnish学习以及CDN的原理

    一.varnish学习Web Page Cache: squid --> varnish 程序的运行具有局部性特征: 时间局部性:一个数据被访问过之后,可能很快会被再次访问到: 空间局部性:一个 ...

  3. Scheme来实现八皇后问题(1)

    版权申明:本文为博主窗户(Colin Cai)原创,欢迎转帖.如要转贴,必须注明原文网址 http://www.cnblogs.com/Colin-Cai/p/9768105.html 作者:窗户 Q ...

  4. .NET CORE学习笔记系列(2)——依赖注入[7]: .NET Core DI框架[服务注册]

    原文https://www.cnblogs.com/artech/p/net-core-di-07.html 包含服务注册信息的IServiceCollection对象最终被用来创建作为DI容器的IS ...

  5. Operation category READ is not supported in state standby

    Namenode 开启HA之后,由于zookeeper异常,出现脑裂现象 执行 $./hdfs haadmin -getServiceState nn1                         ...

  6. DeveloperGuide Hive UDF

    Creating Custom UDFs First, you need to create a new class that extends UDF, with one or more method ...

  7. i春秋 百度杯”CTF比赛 十月场 login

    出现敏感的信息,然后进行登录 登录成功发现奇怪的show 然后把show放到发包里面试一下 出现了源码,审计代码开始 出flag的条件要user 等于春秋 然后进行login来源于反序列化后的logi ...

  8. IDEA+API && SPI

    JAVA中API和SPI的区别:https://blog.csdn.net/quanaianzj/article/details/82500019

  9. 深入理解 path-to-regexp.js 及源码分析

    阅读目录 一:path-to-regexp.js 源码分析如下: 二:pathToRegexp 的方法使用 回到顶部 一:path-to-regexp.js 源码分析如下: 我们在vue-router ...

  10. Atcoder Dwango Programming Contest V

    模拟,做了ABC三题. D难一些,就不会了. 中规中矩的吧... Atcoder DPCV B 题意:给一个序列,求出所有的子串和中AND值最大的k个数的AND. 思路:既然要求AND,那么肯定按位考 ...