|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 皮卡丘大王 于 2023-1-1 23:03 编辑
这个七段数码管绘制为什么没有颜色,也不显示年月日
import turtle
import time
def drawGap():
turtle.penup()
turtle.fd(8)
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", 25, "normal"))
turtle.pencolor("green")
turtle.fd(40)
elif i == '月':
turtle.write('月', font=("Arial", 25, "normal"))
turtle.pencolor("yellow")
turtle.fd(40)
elif i == '日':
turtle.write('日', font=("Arial", 25, "normal"))
else:
drawDigit(eval(i))
def main():
turtle.setup(1000, 350, 200, 200)
turtle.penup()
turtle.fd(-300)
turtle.pensize(5)
date = "20221209"
drawDate(date)
turtle.hideturtle()
turtle.done()
main()
date = "20221209" 这个没有年‘、月、日三个字符串哦
import turtle
import time
def drawGap():
turtle.penup()
turtle.fd(8)
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", 25, "normal"))
turtle.pencolor("green")
turtle.fd(40)
elif i == '月':
turtle.write('月', font=("Arial", 25, "normal"))
turtle.pencolor("yellow")
turtle.fd(40)
elif i == '日':
turtle.write('日', font=("Arial", 25, "normal"))
else:
drawDigit(eval(i))
def main():
turtle.setup(1000, 350, 200, 200)
turtle.penup()
turtle.fd(-300)
turtle.pensize(5)
date = "2022年12月09日"
drawDate(date)
turtle.hideturtle()
turtle.done()
main()
|
|