画一个红色的五角星

  1. from turtle import *
  2. color('red','red')
  3. begin_fill()
  4. for i in range(5):
  5. fd(200)
  6. rt(144)
  7.  
  8. end_fill()
  9. done()

效果图:

画一条蟒蛇

  1. #PythonDraw.py
  2. import turtle
  3. #turtle.setup(650,350,200,200)
  4. turtle.penup()
  5. turtle.fd(-250)
  6. turtle.pendown()
  7. turtle.pensize(25)
  8. turtle.pencolor("purple")
  9. turtle.seth(-40)
  10. for i in range(4):
  11. turtle.circle(40,80)
  12. turtle.circle(-40,80)
  13. turtle.circle(40,80/2)
  14. turtle.fd(40)
  15. turtle.circle(16,180)
  16. turtle.fd(40*2/3)

效果图:

画一组内切圆

  1. import turtle
  2. turtle.pensize(2)
  3. turtle.circle(10)
  4. turtle.circle(40)
  5. turtle.circle(80)
  6. turtle.circle(120)

效果图:

画一个社会人小猪佩奇,代码是借鉴某位大佬的

  1. from turtle import *
  2. def nose(x,y):
  3. pu()
  4. goto(x,y)
  5. pd()
  6. seth(-30)
  7. begin_fill()
  8. a=0.4
  9. for i in range(120):
  10. if 0<=i<30 or 60<=i<90:
  11. a=a+0.08
  12. lt(3)
  13. fd(a)
  14. else:
  15. a=a-0.08
  16. lt(3)
  17. fd(a)
  18. end_fill()
  19.  
  20. pu()
  21. seth(90)
  22. fd(25)
  23. seth(0)
  24. fd(10)
  25. pd()
  26. pencolor(255,155,192)
  27. seth(10)
  28. begin_fill()
  29. circle(5)
  30. color(160,82,45)
  31. end_fill()
  32.  
  33. pu()
  34. seth(0)
  35. fd(20)
  36. pd()
  37. pencolor(255,155,192)
  38. seth(10)
  39. begin_fill()
  40. circle(5)
  41. color(160,82,45)
  42. end_fill()
  43.  
  44. def head(x,y):
  45. color((255,155,192),"pink")
  46. pu()
  47. goto(x,y)
  48. seth(0)
  49. pd()
  50. begin_fill()
  51. seth(180)
  52. circle(300,-30)
  53. circle(100,-60)
  54. circle(80,-100)
  55. circle(150,-20)
  56. circle(60,-95)
  57. seth(161)
  58. circle(-300,15)
  59. pu()
  60. goto(-100,100)
  61. pd()
  62. seth(-30)
  63. a=0.4
  64. for i in range(60):
  65. if 0<=i<30 or 60<=i<90:
  66. a=a+0.08
  67. lt(3)
  68. fd(a)
  69. else:
  70. a=a-0.08
  71. lt(3)
  72. fd(a)
  73. end_fill()
  74.  
  75. def ears(x,y):
  76. color((255,155,192),"pink")
  77. pu()
  78. goto(x,y)
  79. pd()
  80. begin_fill()
  81. seth(100)
  82. circle(-50,50)
  83. circle(-10,120)
  84. circle(-50,54)
  85. end_fill()
  86.  
  87. pu()
  88. seth(90)
  89. fd(-12)
  90. seth(0)
  91. fd(30)
  92. pd()
  93. begin_fill()
  94. seth(100)
  95. circle(-50,50)
  96. circle(-10,120)
  97. circle(-50,56)
  98. end_fill()
  99.  
  100. def eyes(x,y):
  101. color((255,155,192),"white")
  102. pu()
  103. seth(90)
  104. fd(-20)
  105. seth(0)
  106. fd(-95)
  107. pd()
  108. begin_fill()
  109. circle(15)
  110. end_fill()
  111.  
  112. color("black")
  113. pu()
  114. seth(90)
  115. fd(12)
  116. seth(0)
  117. fd(-3)
  118. pd()
  119. begin_fill()
  120. circle(3)
  121. end_fill()
  122.  
  123. color((255,155,192),"white")
  124. pu()
  125. seth(90)
  126. fd(-25)
  127. seth(0)
  128. fd(40)
  129. pd()
  130. begin_fill()
  131. circle(15)
  132. end_fill()
  133.  
  134. color("black")
  135. pu()
  136. seth(90)
  137. fd(12)
  138. seth(0)
  139. fd(-3)
  140. pd()
  141. begin_fill()
  142. circle(3)
  143. end_fill()
  144.  
  145. def cheek(x,y):
  146. color((255,155,192))
  147. pu()
  148. goto(x,y)
  149. pd()
  150. seth(0)
  151. begin_fill()
  152. circle(30)
  153. end_fill()
  154.  
  155. def mouth(x,y):
  156. color(239,69,19)
  157. pu()
  158. goto(x,y)
  159. pd()
  160. seth(-80)
  161. circle(30,40)
  162. circle(40,80)
  163.  
  164. def body(x,y):
  165. color("red",(255,99,71))
  166. pu()
  167. goto(x,y)
  168. pd()
  169. begin_fill()
  170. seth(-130)
  171. circle(100,10)
  172. circle(300,30)
  173. seth(0)
  174. fd(230)
  175. seth(90)
  176. circle(300,30)
  177. circle(100,3)
  178. color((255,155,192),(255,100,100))
  179. seth(-135)
  180. circle(-80,63)
  181. circle(-150,24)
  182. end_fill()
  183.  
  184. def hands(x,y):
  185. color((255,155,192))
  186. pu()
  187. goto(x,y)
  188. pd()
  189. seth(-160)
  190. circle(300,15)
  191. pu()
  192. seth(90)
  193. fd(15)
  194. seth(0)
  195. fd(0)
  196. pd()
  197. seth(-10)
  198. circle(-20,90)
  199.  
  200. pu()
  201. seth(90)
  202. fd(30)
  203. seth(0)
  204. fd(237)
  205. pd()
  206. seth(-20)
  207. circle(-300,15)
  208. pu()
  209. seth(90)
  210. fd(20)
  211. seth(0)
  212. fd(0)
  213. pd()
  214. seth(-170)
  215. circle(20,90)
  216.  
  217. def foot(x,y):
  218. pensize(10)
  219. color((240,128,128))
  220. pu()
  221. goto(x,y)
  222. pd()
  223. seth(-90)
  224. fd(40)
  225. seth(-180)
  226. color("black")
  227. pensize(15)
  228. fd(20)
  229.  
  230. pensize(10)
  231. color((240,128,128))
  232. pu()
  233. seth(90)
  234. fd(40)
  235. seth(0)
  236. fd(90)
  237. pd()
  238. seth(-90)
  239. fd(40)
  240. seth(-180)
  241. color("black")
  242. pensize(15)
  243. fd(20)
  244.  
  245. def tail(x,y):
  246. pensize(4)
  247. color((255,155,192))
  248. pu()
  249. goto(x,y)
  250. pd()
  251. seth(0)
  252. circle(70,20)
  253. circle(10,330)
  254. circle(70,30)
  255.  
  256. def setting():
  257. pensize(4)
  258. hideturtle()
  259. colormode(255)
  260. color((255,155,192),"pink")
  261. setup(840,500)
  262. speed(10)
  263.  
  264. def main():
  265. setting()
  266. nose(-100,100)
  267. head(-69,167)
  268. ears(0,160)
  269. eyes(0,140)
  270. cheek(80,10)
  271. mouth(-20,30)
  272. body(-32,-8)
  273. hands(-56,-45)
  274. foot(2,-177)
  275. tail(148,-155)
  276. done()
  277.  
  278. main()

效果极佳:

简单总结一下好了,其实turtle库还是非常有用的,以后可以画张很有创意的图片去表白女神了,讲不好那天就用上了呢:

显示器和turtle窗体的左上角都是原点
turtle.setup(width,height,startx,starty)设置窗体大小及位置,后面两个参数可选,非必需
空间坐标:绝对坐标:右方向x轴,上方向为y轴,正中心为原点,turtle.goto(x,y)让在任何位置的海龟到达指定的位置
海龟坐标:turtle.fd(d)海龟向前行多少像素
turtle.bk(d)向海龟的反方向运行
turtle.circle(r,angle)以海龟左边的某一点为圆心进行曲线运行
角度坐标:绝对角度:turtle.seth(angle)angle为绝对度数,表示改变海龟的运行方向
海龟角度:turtle.right(angle),turtle.left(angle)改变海龟的运行方向
RGB体系:turtle.colormode(mode)mode=1.0则改用0和1表示,mode=255则改用255和0表示,默认为小数
库引用:import <库名>,from <库名> import *或者from <库名> import <函数名>,import <库名> as <库别名>
画笔控制函数:turtle.penup()别名:turtle.pu()抬起画笔,turtle.pendown()别名:turtle.pd()落下画笔,turtle.pensize(width)别名:turtle.width(width)设置画笔宽度,turtle.pencolor(color)设置画笔颜色,color有三种方式,颜色字符串,或者RGB小数值,或者RGB元组值,例如:turtle.pencolor((0.63,0.13,0.94))
运动控制函数:turtle.circle(r,angle),r(海龟左方向)表示半径,angle表示绘制的角度,默认是360度
方向控制函数:turtle.seth(angle)改变海龟的行进方向,顺时针转向

Python学习之turtle绘图篇的更多相关文章

  1. Python学习笔记之基础篇(-)python介绍与安装

    Python学习笔记之基础篇(-)初识python Python的理念:崇尚优美.清晰.简单,是一个优秀并广泛使用的语言. python的历史: 1989年,为了打发圣诞节假期,作者Guido开始写P ...

  2. Python学习总结之一 -- 基础篇

    Python学习第一篇 一:写在前面 啊,最近我的新博客一直都没有更新学习内容了,只是最近一直都在忙着寻找实习机会(或许这只是一个借口,真实原因是我太懒惰了,改改改!).终于今天又投递了几个新的实习职 ...

  3. python 学习分享-装饰器篇

    本篇内容为偷窃的~哈哈,借用一下,我就是放在自己这里好看. 引用地址:http://www.cnblogs.com/rhcad/archive/2011/12/21/2295507.html 第一步: ...

  4. Python学习【第五篇】:面向对象及相关

    面向对象基础 基础内容介绍详见一下两篇博文: 面向对象初级篇 面向对象进阶篇 其他相关 一.isinstance(obj, cls) 检查是否obj是否是类 cls 的对象 1 2 3 4 5 6 c ...

  5. Python学习之turtle库和蟒蛇绘制程序

    Python的函数库 Python语言与C语言Java类似,可以大量使用外部函数库包含在安装包中的函数库:. 比如math, random, turtle等其他函数库,其他函数库用户根据代码需求自行安 ...

  6. python学习之路入门篇

    本文是up学习python过程中遇到的一些问题及总结归纳,本小节是入门篇. python基本语法 循环.分支不多赘述. 模块:一个.py文件就是一个模块. 文件和异常 模式 含义解释 “r” 读模式 ...

  7. Python学习【第十一篇】模块(1)

    模块 模块让你能够有逻辑地组织你的Python代码段. 把相关的代码分配到一个模块里能让你的代码更好用,更易懂. 模块也是Python对象,具有随机的名字属性用来绑定或引用. 简单地说,模块就是一个保 ...

  8. Python学习【第四篇】用户输入及判断

    用户输入: 例1.写一个用户输入密码的小程序,流程如下: 1.用户输入自己的用户名 2.打印"Hello+用户名" #!/usr/bin/env python #name = ra ...

  9. 初学者的python学习笔记1——作业篇

    既然是学习,作业必不可少,其实在看后面讲思路之前还是感觉自己写的不错,但是和后面一对比,感觉实在是想的太片面太肤浅了,还需要太多太多改进的地方. 首先放一下作业要求. 最开始做的时候真的是完全按照字面 ...

随机推荐

  1. python机器学习笔记:EM算法

    EM算法也称期望最大化(Expectation-Maximum,简称EM)算法,它是一个基础算法,是很多机器学习领域的基础,比如隐式马尔科夫算法(HMM),LDA主题模型的变分推断算法等等.本文对于E ...

  2. mysql5.7 derived_merge=on 影响你的查询了吗?

    衍生表的优化:合并 | 具化 一.mysql优化器对于衍生表的优化处理可以从两方面进行: 将衍生表合并到外部查询 将衍生表具化为内部临时表 1.示例 1: SELECT * FROM (SELECT ...

  3. 我的linux学习日记day3

    ifconfig  查看网卡信息 uname 查看系统内核.版本信息 cat /etc/redhat-release uptime 查看系统负载信息 top命令的第一行信息 free 查看内存信息 f ...

  4. RobotFramework Selenium2Library 关键字详解

    *** Settings *** Library Selenium2Library *** Keywords *** Checkbox应该不被选择 [Arguments] ${locator} Che ...

  5. vue项目中使用less

    1.安装less less-loader npm i -D less less-loader 2.在 .vue文件中使用lang="less"和@import // home.le ...

  6. Error: ER_BAD_FIELD_ERROR: Unknown column 'xxx' in 'where clause'

    node中调用mysql模块读写时候,如果直接插入字符串: connection.query('SELECT * from  users WHERE name=' + data.name , call ...

  7. nginx配置之站点服务请求功能配置

    站点服务请求功能配置:html/ nginx.conf中的http{}中的server{}: server { listen 85; server_name localhost; #charset k ...

  8. Django视图函数函数之视图装饰器

    FBV模式装饰器: 普通函数的装饰器(语法糖@) views.py from django.shortcuts import render def wrapper(f): def inner(*arg ...

  9. win10安装nodejs,修改全局依赖位置和环境变量配置

    为什么要修改nodejs全局依赖位置? nodejs全局依赖安装默认位置在C盘,导致C盘文件太大,影响电脑运行速度. 步骤: 安装nodejs(在node官网下载并安装) 查看nodejs版本(在命令 ...

  10. poj3376 KMP+字典树求回文串数量(n*n)

    Finding Palindromes Time Limit: 10000MS   Memory Limit: 262144K Total Submissions: 4043   Accepted: ...