Python海龟绘图,画数码晶体管日期 (北理工Python课上代码,加入时分秒)
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了Python海龟绘图,画数码晶体管日期 (北理工Python课上代码,加入时分秒),小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1878字,纯文字阅读大概需要3分钟。
内容图文
![Python海龟绘图,画数码晶体管日期 (北理工Python课上代码,加入时分秒)](/upload/InfoBanner/zyjiaocheng/610/b2a5ca6d4fe24be89164fcf630139cf1.jpg)
效果图
各子函数功能
drawLine(draw) 画一条线
drawDight(dight) 画一个数字
drawDate(date) 画一组数字
完整代码
import turtle,time
def drawLine(draw):
turtle.pendown() if draw else turtle.penup()
turtle.fd(40)
turtle.right(90)
def drawDight(dight):
drawLine(True) if dight in [2,3,4,5,6,8,9] else drawLine(False)
drawLine(True) if dight in [0,1,3,4,5,6,7,8,9] else drawLine(False)
drawLine(True) if dight in [0,2,3,5,6,8,9] else drawLine(False)
drawLine(True) if dight in [0,2,6,8] else drawLine(False)
turtle.left(90)
drawLine(True) if dight in [0,4,5,6,8,9] else drawLine(False)
drawLine(True) if dight in [0,2,3,5,6,7,8,9] else drawLine(False)
drawLine(True) if dight in [0,1,2,3,4,7,8,9] else drawLine(False)
turtle.right(180)
turtle.penup()
turtle.fd(20)
def drawDate(date):
turtle.pencolor("red")
for i in date:
if i == '-':
turtle.write('年',font=("微软雅黑",32,"normal"))
turtle.pencolor("green")
turtle.fd(80)
elif i == '=':
turtle.write('月', font=("微软雅黑", 32, "normal"))
turtle.pencolor("blue")
turtle.fd(80)
elif i == '+':
turtle.write('日', font=("微软雅黑", 32, "normal"))
turtle.pencolor("red")
turtle.fd(80)
elif i == '/':
turtle.write('时', font=("微软雅黑", 32, "normal"))
turtle.pencolor("green")
turtle.fd(80)
elif i == '*':
turtle.write('分', font=("微软雅黑", 32, "normal"))
turtle.pencolor("blue")
turtle.fd(80)
elif i == '.':
turtle.write('秒', font=("微软雅黑", 32, "normal"))
turtle.fd(80)
else:
drawDight(eval(i))
if __name__ == '__main__':
# turtle.setup() 我用的是pycharm,所以没有设置画布,idle下需要设置
turtle.penup()
turtle.fd(-350)
turtle.pensize(5)
turtle.speed(1000) #速度再大也没感觉了
drawDate(time.strftime('%Y-%m=%d+',time.localtime()))
#这里千万不要用time.gmtime()),获取的是UTC时区(0时区)的struct_time
#踩了半天坑
turtle.right(90)
turtle.fd(120)
turtle.right(90)
turtle.fd(660)
turtle.right(180)
drawDate(time.strftime('%H/%M*%S.',time.localtime()))
turtle.hideturtle()
turtle.done()
内容总结
以上是互联网集市为您收集整理的Python海龟绘图,画数码晶体管日期 (北理工Python课上代码,加入时分秒)全部内容,希望文章能够帮你解决Python海龟绘图,画数码晶体管日期 (北理工Python课上代码,加入时分秒)所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。