python使用turtle库绘制树
2018-06-25 08:31
1666 查看
本文实例为大家分享了python使用turtle库绘制树的具体代码,供大家参考,具体内容如下
# -*- coding: utf-8 -*- """ Spyder Editor This is a temporary script file. """ import turtle, datetime def drawGap(): #绘制数码管间隔 turtle.penup() turtle.fd(5) def drawLine(draw): #绘制单段数码管 drawGap() turtle.pendown() if draw else turtle.penup() turtle.fd(40) drawGap() turtle.right(90) def drawDigit(d): #根据数字绘制七段数码管 drawLine(True) if d in [2,3,4,5,6,8,9] else drawLine(False) drawLine(True) if d in [0,1,3,4,5,6,7,8,9] else drawLine(False) drawLine(True) if d in [0,2,3,5,6,8,9] else drawLine(False) drawLine(True) if d in [0,2,6,8] else drawLine(False) turtle.left(90) drawLine(True) if d in [0,4,5,6,8,9] else drawLine(False) drawLine(True) if d in [0,2,3,5,6,7,8,9] else drawLine(False) drawLine(True) if d in [0,1,2,3,4,7,8,9] else drawLine(False) turtle.left(180) turtle.penup() turtle.fd(20) def drawDate(date): turtle.pencolor("red") for i in date: if i == '-': turtle.write('年',font=("Arial", 18, "normal")) turtle.pencolor("green") turtle.fd(40) elif i == '=': turtle.write('月',font=("Arial", 18, "normal")) turtle.pencolor("blue") turtle.fd(40) elif i == '+': turtle.write('日',font=("Arial", 18, "normal")) else: drawDigit(eval(i)) def main(): turtle.setup(800, 350, 200, 200) turtle.penup() turtle.fd(-350) turtle.pensize(5) drawDate(datetime.datetime.now().strftime('%Y-%m=%d+')) turtle.hideturtle() main()
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
您可能感兴趣的文章:
相关文章推荐
- python使用turtle绘制分形树
- 使用Python中的Turtle库绘制简单的图形
- python使用turtle库绘制时钟
- python使用turtle库绘制时钟
- Python编程练习:使用 turtle 库完成玫瑰花的绘制
- Python 绘图—使用Turtle库绘制动态钟表
- Python编程练习:使用 turtle 库完成六边形的绘制
- Python使用Turtle模块绘制五星红旗代码示例
- 使用Python的turtle库实现七段数码管绘制
- Python编程练习:使用 turtle 库完成正方形的绘制
- Python3使用turtle绘制超立方体图形示例
- 使用python中turtle库绘制图形
- python使用turtle库与random库绘制雪花
- python使用pygal进行绘制数据图表和监控图表
- python 使用turtle画国旗
- python使用PyGame绘制图像并保存为图片文件的方法
- 在Python中使用matplotlib模块绘制数据图的示例
- 使用Python标准库中的wave模块绘制乐谱的简单教程
- python实战二:使用CSV数据绘制带数据标志的折线图(matplotlib)
- libsvm在python下的使用及用绘制ROC曲线