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. *【Python】【demo实验31】【练习实例】【使用turtle画小猪佩奇】

    如下图小猪佩奇: 要求使用turtle画小猪佩奇: 源码: # encoding=utf-8 # -*- coding: UTF-8 -*- # 使用turtle画小猪佩奇 from turtle i ...

  2. Python之turtle库-小猪佩奇

    Python之turtle库-小猪佩奇 #!/usr/bin/env python # coding: utf-8 # Python turtle库官方文档:https://docs.python.o ...

  3. python运用turtle 画出汉诺塔搬运过程

    python运用turtle 画出汉诺塔搬运过程 1.打开 IDLE 点击File-New File 新建立一个py文件 2.向py文件中输入如下代码 import turtle class Stac ...

  4. 用CSS画小猪佩奇,你就是下一个社会人! js将“I am a coder”反转成 “coder a am I”,不许用split,join,subString,reverse;求解方法三

    用CSS画小猪佩奇,你就是下一个社会人!   欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 作者:江志耿 | 腾讯TEG网络工程师 我是佩奇,哼,这是我的弟弟乔治,呱呱,这是我的妈妈,嚯 ...

  5. python 画小猪佩奇

    转自:python画个小猪佩奇 # -*- coding: utf-8 -*- """ Created on Mon May 20 11:36:03 2019 @auth ...

  6. 使用canvas 代码画小猪佩奇

    最近不是小猪佩奇很火嘛!!! 前几天 在知乎 看见了别人大佬用python写的 小猪佩奇,  顿时想学 ,可是 自己 没学过python(自己就好爬爬图片,,,,几个月没用 又丢了) 然后 就想画一个 ...

  7. 用CSS画小猪佩奇,你就是下一个社会人!

    欢迎大家前往腾讯云+社区,获取更多腾讯海量技术实践干货哦~ 作者:江志耿 | 腾讯TEG网络工程师 我是佩奇,哼,这是我的弟弟乔治,呱呱,这是我的妈妈,嚯,这是我的爸爸,嚯~ 背景 小猪佩奇已经火了好 ...

  8. 用python画小猪佩奇(非原创)

    略作改动: # coding:utf-8 import turtle as t t.screensize(400, 300, "blue") t.pensize(4) # 设置画笔 ...

  9. 利用python画小猪佩奇

    import turtle as t t.pensize(4) t.hideturtle() t.colormode(255) t.color((255,155,192),"pink&quo ...

随机推荐

  1. nginx uwsgi wsgi django 这些东西究竟是什么关系

    有太多的文章告诉我们nginx uwsgi django 这些东西怎么用了,太多的人知道这些东西的怎么使用,怎么配置,怎么优化,但是还是有一部分人比如我这种水货不知道这些东西到底是啥,为啥一个项目的发 ...

  2. oracle--循环PL/SQL--demo1---

    --简单的条件判断if–then --编写一个过程,可以输入一个雇员名,如果该雇员的工资低于2000,就给该员工工资增加10%. create or replace procedure sp_pro6 ...

  3. 使用变参函数实现pwd命令

    #include "stdafx.h"#include <Windows.h> #define DIRNAME_LEN (MAX_PATH+2) BOOL PrintS ...

  4. python操作sql server2008 pyodbc

    使用Python通过PyODBC连接数据的注意事项 今天使者用PyODBC连接数据库,试了很久才出来,现把一些心得体会和大家分享! 一.PyODBC的下载地址: http://code.google. ...

  5. Zeppelin的入门使用系列之创建新的Notebook(一)

    不多说,直接上干货! 前期博客 hadoop-2.6.0.tar.gz + spark-1.6.1-bin-hadoop2.6.tgz + zeppelin-0.5.6-incubating-bin- ...

  6. overflow: auto;溢出自动显示

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. CSS多列布局Multi-column、伸缩布局Flexbox、网格布局Grid详解

    新css属性为我们提供了更加便捷的网页布局方式.来自微软的thomas lewis将带你认识去Grid Alignment,Flexibox Box以及Multi-column Layout这三大领域 ...

  8. nodejs assert 模块

    assert模块是Node的内置模块,主要用于断定.如果表达式不符合预期,就抛出一个错误.该模块提供11个方法,但只有少数几个是常用的. 1.assert() assert(value[, messa ...

  9. 30、 bowtie和bowtie2使用条件区别及用法

    转载:http://blog.csdn.net/soyabean555999/article/details/62235577 一.转录组还是基因组? map常用的工具有bowtie/bowtie2, ...

  10. Struts2学习第三课 访问Web资源

    1.什么是WEB资源? HttpServletRequest,HttpSession,ServletContext等原生的Servlet API. 2.为什么访问WEB资源? B/S的应用的Contr ...