说明:

利用python自带的海龟库turtle绘制多彩图像,并进行当前日期绘制。

环境:

python 3.6.8

import turtle
import random
import time__Pen = turtle.Pen()__Pen.hideturtle()
turtle.bgcolor("#000000")
colors = ['red', 'yellow', 'blue', 'green', 'orange', 'purple', 'white', 'gray']
t = turtle.Pen()
t.hideturtle()
t.pencolor(random.choice(colors))
t.penup()
t.speed(0)
t.setheading(270)
t.forward(100)
t.setheading(0)
t.speed(4)
t.pendown()
__Pen.penup()
__Pen.setheading(270)
__Pen.forward(75)
__Pen.setheading(0)
__Pen.pendown()
t.fillcolor(random.choice(colors))
t.begin_fill()
t.circle(100)
t.end_fill()
__Pen.pencolor(random.choice(colors))
__Pen.fillcolor(random.choice(colors))
__Pen.begin_fill()
__Pen.circle(75)
__Pen.end_fill()
c = turtle.Pen()
c.hideturtle()
c.penup()
c.goto(0, (-50))
c.setheading(0)
c.pendown()
c.pencolor(random.choice(colors))
c.fillcolor(random.choice(colors))
c.begin_fill()
c.circle(50)
c.end_fill()
d = turtle.Pen()
d.hideturtle()
d.penup()
d.goto(0, (-25))
d.setheading(0)
d.pendown()
d.pencolor(random.choice(colors))
d.fillcolor(random.choice(colors))
d.begin_fill()
d.circle(25)
d.end_fill()
time.sleep(1)
t.clear()
time.sleep(1)
__Pen.clear()
time.sleep(1)
c.clear()
time.sleep(1)
d.clear()
e = turtle.Pen()
e.speed(0)
e.hideturtle()
sides = random.randint(2, 6)
for x in range(60):e.pencolor(colors[(x % sides)])e.forward(((x * 3) / sides + x))e.left(73)e.pensize(((x * sides) / 200))
t.penup()
__Pen.penup()
c.penup()
d.penup()
t.goto((-105), 105)
__Pen.goto(105, (-105))
c.goto(105, 105)
d.goto((-105), (-105))
t.pendown()
__Pen.pendown()
c.pendown()
d.pendown()
t.setheading(225)
t.circle(150, 90)
__Pen.setheading(45)
__Pen.circle(150, 90)
c.setheading(135)
c.circle(150, 90)
d.setheading(315)
d.circle(150, 90)
t.clear()
__Pen.clear()
c.clear()
d.clear()
e.clear()def drawGap():turtle.penup()turtle.forward(5)def drawLine(draw):drawGap()turtle.pendown() if draw else turtle.penup()turtle.forward(40)drawGap()turtle.right(90)def drawDigit(digit):drawLine(True) if digit in [2, 3, 4, 5, 6, 8, 9] else drawLine(False)drawLine(True) if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False)drawLine(True) if digit in [0, 2, 3, 5, 6, 8, 9] else drawLine(False)drawLine(True) if digit in [0, 2, 6, 8] else drawLine(False)turtle.left(90)drawLine(True) if digit in [0, 4, 5, 6, 8, 9] else drawLine(False)drawLine(True) if digit in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False)drawLine(True) if digit in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False)turtle.left(180)turtle.penup()turtle.forward(20)def drawDate(date):turtle.pencolor('red')for i in date:if (i == '-'):turtle.write('年', font = ('Arial', 24, 'normal'))turtle.pencolor('yellow')turtle.forward(40)elif (i == '='):turtle.write('月', font = ('Arial', 24, 'normal'))turtle.pencolor('green')turtle.forward(40)elif (i == '+'):turtle.write('日', font = ('Arial', 24, 'normal'))else:drawDigit(eval(i))def main():turtle.setup(800, 350, 200, 200)turtle.penup()turtle.forward((-300))turtle.pensize(5)drawDate(time.strftime('%Y-%m=%d+', time.gmtime()))turtle.hideturtle()turtle.done()main()

运行结果:

2.基于turtle库的多彩图像及日期绘制相关推荐

  1. python turtle库画图案-Python基础图形绘制库——turtle

    (1).介绍 turtle库也叫海龟库,是turtle绘图体系的Python实现.turtle库是Python语言的标准库之一,是入门级的图形绘制函数库. turtle绘图体系:也叫海龟绘图系统,它是 ...

  2. 1.基于turtle库的小动物绘制及分辨

    说明: 利用python自带的海龟库turtle绘制小动物,并进行动物名称猜测. 环境: python 3.6.8 import turtle as t t.colormode(255) def qu ...

  3. Python编程练习:使用 turtle 库完成叠边形的绘制

    绘制效果: 源代码: # 叠边形 import turtle turtle.setup(650,350,200,200) turtle.penup() turtle.fd(-100) turtle.l ...

  4. python七段数码管绘制单个数字_使用Python的turtle库实现七段数码管绘制

    七段数码管绘制: 七段数码管是由7段数码管拼接而成,每段有亮或不亮两种情况,改进的七段数码管还包括一个小数点位置. 七段数码管能形成2^7=128种状态,其中部分状态能够显示易于人们理解的数字或字母含 ...

  5. 用python画小动物大全_python3用turtle库进行绘制小猪佩奇图案

    晚上闲着无事,深入学习这个turtle用法,就做了小猪佩奇图 附上代码: # coding: utf-8 #功能:绘画小猪佩奇 import turtle as t t.screensize(400, ...

  6. Python·运用turtle库仿制勇士队logo

    目录 前言 一.turtle库是什么? 二.绘制步骤 1.引入库 2.开始绘制 3.效果图 1).预期效果 2).实际效果 总结 前言 经历了总决赛败北.克莱赛季报销.杜兰特转队.新队员欠磨合等一系列 ...

  7. python turtle库介绍_turtle库使用简介

    turtle库使用简介 2020-09-22 python之绘制图形库turtleturtle库是python的基础绘图库,官方手册这个库被介绍为一个最常用的用来给孩子们介绍编程知识的方法库,其主要是 ...

  8. python random库画多彩蟒蛇,Python Turtle库绘制蟒蛇

    使用Python Turtle库来绘制蟒蛇 import turtle引入了海龟绘图体系 使用setup函数,设定了一个宽650像素和高350像素的窗体,其位置左上角坐标是200,200 说明位置在距 ...

  9. 使用Turtle库绘制图像----哆啦A梦

    使用Turtle库绘制图像----哆啦A梦 前言 Turtle库是Python中的一个绘图的函数库. 老师布置的作业,让我们设计图像 呜呜呜~好难过,毕竟太死了这个工具.. 方法都很简单,基本都是一样 ...

最新文章

  1. android 渠道包 占位符配置,Android打包
  2. Jenkins学习四:Jenkins 邮件配置
  3. SAP 自定义 Table 中的小陷阱
  4. 无监督领域迁移及文本表示学习的相关进展
  5. numpy安装失败-小失误
  6. python进阶指南_Python特性工程动手指南
  7. 数据完整性(python 版)
  8. android语法高亮插件,安卓语法高亮编辑器 HighlightTextEditor
  9. 编程迷宫_跟我学编程第十期——迷宫游戏
  10. 吴宗宪经典暴笑语录(笑不死你肯定是个异类)
  11. pdfpcell输出换行_poi导出Excel(cell单元格里的一串文字,换行显示,设置字体)...
  12. 远程桌面(3389)复制(拖动)文件
  13. 用Visual C#.NET编写服务器日期控件
  14. 区块链ICO是什么意思?回答所有你关于ICO的问题
  15. download failed: assets/main/import/09/09f53264-cd95-4751-99ad-d516c164dd80._cconb.dbbin, status: 40
  16. 200行代码搞定一个购物网站+电影站+APP
  17. JavaScript - 语言基础
  18. excel批量改名字(含识别区分)
  19. 非线性规划----经济调度(Python实现)
  20. 再读杨绛_RWERWERWE_96921_新浪博客

热门文章

  1. linux下C++开发
  2. OPPO R9s领衔,情人节哪些手机适合作为情侣手机送给对方
  3. v58.03 鸿蒙内核源码分析(环境脚本) | 编译鸿蒙原来很简单 | 百篇博客分析HarmonyOS源码
  4. java计算机毕业设计健身房管理系统MyBatis+系统+LW文档+源码+调试部署
  5. OpenGL光照贴图
  6. CentOS 7安装MySQL 非yum或rpm安装
  7. 爱源于仰慕,汲于仰慕
  8. oracle ltrim函数作用,oracle ltrim函数的用法
  9. 四旋翼无人机学习之准备篇(一)
  10. java计算机毕业设计老年人健康饮食管理系统源码+数据库+lw文档+系统