时钟

  1. import turtle as t
  2. import datetime as dt
  3.  
  4. #画出背景
  5. game = t.Screen()
  6. game.bgcolor("white")
  7. game.setup(600,600)
  8. game.tracer(0)
  9.  
  10. #定义画笔属性
  11. pen = t.Turtle()
  12. pen.speed(10)
  13. pen.ht()
  14. pen.up()
  15.  
  16. def draw_clock(h,m,s):
  17. #画圈
  18. pen.clear()
  19. pen.up()
  20. pen.color("black")
  21. pen.pensize(3)
  22. pen.seth(0)
  23. pen.goto(0,-210)
  24. pen.down()
  25. pen.circle(210)
  26.  
  27. #画刻度
  28. pen.up()
  29. pen.goto(0,0)
  30. pen.seth(90)
  31.  
  32. #大刻度
  33. for _ in range(12):
  34. pen.fd(190)
  35. pen.down()
  36. pen.fd(20)
  37. pen.up()
  38. pen.goto(0,0)
  39. pen.rt(30)
  40.  
  41. #小刻度
  42. for _ in range(60):
  43. pen.up()
  44. pen.goto(0,0)
  45. pen.rt(6)
  46. pen.fd(200)
  47. pen.down()
  48. pen.color('black')
  49. pen.pensize(2)
  50. pen.fd(10)
  51.  
  52. #画秒针
  53. pen.up()
  54. pen.home()
  55. pen.down()
  56. pen.color("red")
  57. pen.pensize(3)
  58. pen.seth(90)
  59. pen.rt(s/60*360)
  60. pen.fd(160)
  61. pen.stamp()
  62.  
  63. #画分针
  64. pen.up()
  65. pen.home()
  66. pen.down()
  67. pen.color("Gold")
  68. pen.pensize(3)
  69. pen.seth(90)
  70. pen.rt(m/60*360)
  71. pen.fd(120)
  72. pen.stamp()
  73.  
  74. #画时针
  75. pen.up()
  76. pen.home()
  77. pen.down()
  78. pen.color("Maroon")
  79. pen.pensize(3)
  80. pen.seth(90)
  81. pen.rt(h/12*360)
  82. pen.fd(80)
  83. pen.stamp()
  84.  
  85. #问候字体
  86. pen.up()
  87. pen.goto(-175,250)
  88. pen.color('orange')
  89. font1 = ('宋体',20,'bold')
  90. hello = "{}年你好!今天是{}月{}日".format(now.year,now.month,now.day)
  91. pen.write(hello,"center",font=font1)
  92.  
  93. while True:
  94. game.update()
  95. now = dt.datetime.now()
  96. draw_clock(now.hour,now.minute,now.second)
  97.  
  98. game.mainloop()

太极图

  1. import turtle
  2.  
  3. def Taichi(R,r):
  4. '''
  5. R:整个大圆半径;
  6. r:两个最小圆半径
  7. '''
  8. #大圆左白右黑
  9. p.up()
  10. p.goto(0,-R)
  11. p.down()
  12. p.pencolor('black')
  13. p.fillcolor('black')
  14. p.begin_fill()
  15. p.circle(R,180)
  16. p.end_fill()
  17. p.pencolor('white')
  18. p.fillcolor('white')
  19. p.begin_fill()
  20. p.circle(R,180)
  21. p.end_fill()
  22.  
  23. #半圆下黑上白
  24. p.pencolor('black')
  25. p.fillcolor('black')
  26. p.begin_fill()
  27. p.circle(R/2,-180)
  28. p.end_fill()
  29. p.right(180)
  30. p.pencolor('white')
  31. p.fillcolor('white')
  32. p.begin_fill()
  33. p.circle(R/2,180)
  34. p.end_fill()
  35.  
  36. #小圆上黑下白
  37. p.up()
  38. p.home()
  39. p.goto(0,R/2-r)
  40. p.down()
  41. p.pencolor('black')
  42. p.fillcolor('black')
  43. p.begin_fill()
  44. p.circle(r)
  45. p.end_fill()
  46.  
  47. p.up()
  48. p.goto(0,-(R/2+r))
  49. p.down()
  50. p.pencolor('white')
  51. p.fillcolor('white')
  52. p.begin_fill()
  53. p.circle(r)
  54. p.end_fill()
  55.  
  56. if __name__ == '__main__':
  57. s = turtle.Screen()
  58. s.bgcolor('Silver')
  59. s.screensize(800,800)
  60. p = turtle.Turtle()
  61. p.shape('turtle')
  62. p.ht()
  63. s.tracer(10,0)
  64.  
  65. Taichi(200,30)
  66. s.mainloop()

玫瑰

大部分都是通过调整圆半径、弧度和方向绘制的,过程需一步步尝试,比较繁琐,仅供参考

  1. import turtle
  2.  
  3. #渐大
  4. def increases(a,z,f):
  5. #a:画笔起始大小;z:画笔终止大小;f:渐变拉伸距离
  6. for i in range(a,z):
  7. p.pensize(i)
  8. p.forward(f)
  9.  
  10. #渐小
  11. def smaller(a,z,f):
  12. for i in range(a,z,-1):
  13. p.pensize(i)
  14. p.forward(f)
  15.  
  16. #花蕊
  17. def flower():
  18. #右下
  19. p.up()
  20. p.home()
  21. p.goto(0,0)
  22. p.pencolor('red')
  23. p.left(15)
  24. p.down()
  25. increases(1,7,5)
  26. p.circle(50,70)
  27. p.forward(60)
  28. p.circle(-100,15)
  29. smaller(7,1,5)
  30. #左下
  31. p.up()
  32. p.home()
  33. p.goto(-20,0)
  34. p.left(180)
  35. p.down()
  36. increases(1,7,5)
  37. p.circle(-60,85)
  38. p.forward(60)
  39. p.circle(100,15)
  40. smaller(7,1,5)
  41. #右边
  42. p.up()
  43. p.home()
  44. p.goto(80,250)
  45. p.left(10)
  46. p.down()
  47. increases(1,5,5)
  48. p.circle(-20,120)
  49. p.circle(-130,20)
  50. p.forward(50)
  51. p.circle(100,15)
  52. smaller(5,1,6)
  53. #左边
  54. p.up()
  55. p.home()
  56. p.goto(-110,240)
  57. p.left(180)
  58. p.down()
  59. increases(1,5,5)
  60. p.circle(30,130)
  61. p.circle(130,15)
  62. p.forward(20)
  63. p.circle(-100,35)
  64. smaller(5,1,7)
  65. #左上
  66. p.up()
  67. p.home()
  68. p.goto(0,270)
  69. p.left(150)
  70. p.down()
  71. increases(1,5,5)
  72. p.circle(60,120)
  73. p.circle(60,30)
  74. p.circle(-50,25)
  75. smaller(5,1,5)
  76. #右上
  77. p.up()
  78. p.home()
  79. p.goto(8,271)
  80. p.left(10)
  81. p.down()
  82. increases(1,5,5)
  83. p.circle(-40,80)
  84. p.circle(-30,90)
  85. p.forward(5)
  86. p.circle(250,25)
  87. smaller(4,1,6)
  88. #右中
  89. p.up()
  90. p.home()
  91. p.goto(65,215)
  92. p.left(-95)
  93. p.down()
  94. increases(1,5,5)
  95. p.circle(200,6)
  96. smaller(5,1,7)
  97. #顶右1
  98. p.up()
  99. p.home()
  100. p.goto(-10,260)
  101. p.left(10)
  102. p.down()
  103. increases(1,5,5)
  104. p.circle(-25,120)
  105. p.circle(-20,40)
  106. p.forward(15)
  107. smaller(4,1,6)
  108. #顶右2
  109. p.up()
  110. p.home()
  111. p.goto(-20,240)
  112. p.left(10)
  113. p.down()
  114. increases(1,5,5)
  115. p.circle(-10,200)
  116. smaller(4,1,6)
  117. #顶左1
  118. p.up()
  119. p.home()
  120. p.goto(-20,255)
  121. p.left(165)
  122. p.down()
  123. increases(1,5,5)
  124. p.forward(10)
  125. p.circle(35,190)
  126. p.circle(90,25)
  127. smaller(4,1,5)
  128. #顶左2
  129. p.up()
  130. p.home()
  131. p.goto(-25,240)
  132. p.left(170)
  133. p.down()
  134. increases(1,5,5)
  135. p.circle(15,230)
  136. smaller(4,1,6)
  137.  
  138. def leaf():
  139. #叶子
  140. #左1
  141. p.pencolor('Green')
  142. p.up()
  143. p.home()
  144. p.goto(-80,0)
  145. p.left(220)
  146. p.down()
  147. increases(1,5,5)
  148. p.circle(80,50)
  149. p.circle(-80,60)
  150. smaller(4,1,5)
  151. #左2
  152. p.right(210)
  153. increases(1,5,5)
  154. p.circle(70,80)
  155. p.circle(-100,40)
  156. smaller(4,1,5)
  157. #左3
  158. p.right(100)
  159. increases(1,5,5)
  160. p.circle(-200,40)
  161. smaller(4,1,5)
  162. #左4
  163. p.left(155)
  164. increases(1,5,5)
  165. p.circle(200,45)
  166. smaller(4,1,5)
  167. #右1
  168. p.up()
  169. p.home()
  170. p.goto(45,8)
  171. p.right(45)
  172. p.down()
  173. increases(1,5,5)
  174. p.circle(-300,20)
  175. p.circle(100,40)
  176. smaller(4,1,5)
  177. #右2
  178. p.left(200)
  179. increases(1,5,5)
  180. p.circle(-100,60)
  181. p.circle(70,20)
  182. smaller(5,1,7)
  183. #小叶
  184. p.up()
  185. p.home()
  186. p.goto(70,30)
  187. p.left(20)
  188. p.down()
  189. increases(1,5,5)
  190. p.circle(50,30)
  191. smaller(4,1,5)
  192. p.right(150)
  193. increases(1,5,5)
  194. p.circle(-50,70)
  195. smaller(4,1,5)
  196.  
  197. #花柄
  198. p.up()
  199. p.home()
  200. p.goto(-30,-60)
  201. p.down()
  202. p.right(80)
  203. increases(1,5,5)
  204. p.circle(-700,20)
  205. p.fd(60)
  206. smaller(4,1,5)
  207.  
  208. p.up()
  209. p.home()
  210. p.goto(10,-170)
  211. p.down()
  212. p.right(90)
  213. increases(1,5,5)
  214. p.circle(-700,10)
  215. p.fd(55)
  216. smaller(4,1,5)
  217.  
  218. #刺
  219. p.up()
  220. p.home()
  221. p.goto(-25,-250)
  222. p.down()
  223. p.left(125)
  224. increases(1,5,5)
  225. p.fd(10)
  226. smaller(5,1,5)
  227.  
  228. p.left(165)
  229. increases(1,5,5)
  230. p.fd(40)
  231. smaller(5,1,5)
  232.  
  233. #画布设置
  234. s = turtle.Screen()
  235. s.bgcolor('LightYellow')
  236. s.setup(1400,800)
  237. s.title('送你花花')
  238. s.tracer(1,10)
  239.  
  240. #画笔设置
  241. p = turtle.Turtle()
  242. p.shape('turtle')
  243. p.speed('fastest')
  244. p.ht()

  245. #画花和叶
  246. flower()
  247. leaf()
  248.  
  249. s.mainloop()

Python Turtle模块的简单应用的更多相关文章

  1. Python turtle模块小黄人程序

    讲解Python初级课程的turtle模块,简单粗暴的编写了小黄人的程序.程序还需要进一步优化.难点就是要搞清楚turtle在绘制图形过程中的方向变化. import turtle t = turtl ...

  2. Python turtle 模块可以编写游戏,是真的吗?

    1. 前言 turtle (小海龟) 是 Python 内置的一个绘图模块,其实它不仅可以用来绘图,还可以制作简单的小游戏,甚至可以当成简易的 GUI 模块,编写简单的 GUI 程序. 本文使用 tu ...

  3. Python Logging模块的简单使用

    前言 日志是非常重要的,最近有接触到这个,所以系统的看一下Python这个模块的用法.本文即为Logging模块的用法简介,主要参考文章为Python官方文档,链接见参考列表. 另外,Python的H ...

  4. Python turtle库绘制简单图形

    一.简介 Python中的turtle库是一个直观有趣的图形绘制函数库.turtle库绘制图形有一个基本框架:一个小海龟在坐标系中爬行,其爬行轨迹形成了绘制图形. 二.简单的图形列举 1.绘制4个不同 ...

  5. Python第三方模块--requests简单使用

    1.requests简介 requests是什么?python语言编写的,基于urllib的第三方模块 与urllib有什么关系?urllib是python的内置模块,比urllib更加简洁和方便使用 ...

  6. 用python socket模块实现简单的文件下载

    server端: # ftp server端 import socket, os, time server = socket.socket() server.bind(("localhost ...

  7. python optparse模块的简单用法

    # coding = utf-8 from optparse import OptionParser from optparse import OptionGroup usage = 'Usage: ...

  8. 浅谈Python时间模块

    浅谈Python时间模块 今天简单总结了一下Python处理时间和日期方面的模块,主要就是datetime.time.calendar三个模块的使用.希望这篇文章对于学习Python的朋友们有所帮助 ...

  9. python绘制图形(Turtle模块)

    用python的Turtle模块可以绘制很多精美的图形,下面简单介绍一下使用方法. 需要用到的工具有python,python 的安装这里就不再细说.自行搜索. from turtle import ...

随机推荐

  1. JN_0019:CMD命令窗口常用操作

    1,回到根目录下 cd\ 2,

  2. 【JZOJ 5048】【GDOI2017模拟一试4.11】IQ测试

    题目大意: 判断一个序列是否是另外一个序列删除若干个数字之后得到的. 正文: 我们可以定义两个指针,分别指向长序列和短序列. 拿样例来举例: 如果指针指的数相同,两个指针都往右跳: 如果不同,则指向长 ...

  3. springboot 查看H2数据库

    1  再application.properties文件中,添加 spring.h2.console.enabled=true 2 再浏览器中打开: http://localhost:8080/h2- ...

  4. opencv —— resize、pyrUp 和 pyrDown 图像金字塔(高斯金字塔、拉普拉斯金字塔)与尺寸缩放(向上采样、向下采样)

    我们经常会将某种尺寸的图像转化为其他尺寸的图像,如果需要放大或者缩小图像的尺寸,在 OpenCV 中可以使用如下两种方法: resize 函数,最直接的方法. pyrUp 和 pyrDown 函数,即 ...

  5. selenium获取缓存数据

    爬虫呢有时候数据方便有时候登入获得cookies,以及获取他存缓存中的数据 一.获取缓存中的数据其实很简单js注入就好了 localStorage_1 = driver.execute_script( ...

  6. iptables技术入门

    1- 概述 ___ netfilter/iptables: IP 信息包过滤系统,实际由两个组件netfilter和iptable组成.可以对流入和流出服务器的数据包进行很惊喜的控制.主要工作在OSI ...

  7. 剑指offer-面试题39-数组中出现次数超过一半的数字-抵消法

    /* 题目: 数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字. 例如输入一个长度为9的数组{1,2,3,2,2,2,5,4,2}.由于数字2在数组中出现了5次,超过数组长度的一半,因此输 ...

  8. python-flask模块注入(SSTI)

    前言: 第一次遇到python模块注入是做ctf的时候,当时并没有搞懂原理所在,看了网上的资料,这里做一个笔记. flask基础: 先看一段python代码: from flask import fl ...

  9. 使用mongoose--写接口

    定义数据模型 import mongoose from 'mongoose' mongoose.connect('mongodb://localhost/edu') const advertSchem ...

  10. 重启监听卡在connecting to的问题

    问题描述:lsnrctl start启动监听起不来,一直卡在connecting to半天 1.[oracle@orcl ~]$ lsnrctl start 一直卡半天,就是连不上,按照以前的解决办法 ...