|
| 1 | +import turtle as tl |
| 2 | +import time |
| 3 | +from datetime import datetime,timedelta |
| 4 | + |
| 5 | + |
| 6 | +def drawGap(): #绘制数码管间隔 |
| 7 | + #提起画笔 |
| 8 | + tl.pu() |
| 9 | + # 数码管间隔 |
| 10 | + tl.fd(9) |
| 11 | + |
| 12 | +def drawLine(draw): #绘制单段数码管 |
| 13 | + drawGap() |
| 14 | + tl.pendown() \ |
| 15 | + if draw else tl.penup() |
| 16 | + tl.fd(40) |
| 17 | + drawGap() |
| 18 | + tl.right(90) |
| 19 | + |
| 20 | +def drawDigit(d): #根据数字绘制七段数码管 |
| 21 | + # 每个数字由7段数码管组成 |
| 22 | + drawLine(True) if d in [2, 3, 4, 5, 6, 8, 9] else drawLine(False) |
| 23 | + drawLine(True) if d in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False) |
| 24 | + drawLine(True) if d in [0, 2, 3, 5, 6, 8, 9] else drawLine(False) |
| 25 | + drawLine(True) if d in [0, 2, 6, 8] else drawLine(False) |
| 26 | + tl.left(90) |
| 27 | + # |
| 28 | + drawLine(True) if d in [0, 4, 5, 6, 8, 9] else drawLine(False) |
| 29 | + drawLine(True) if d in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False) |
| 30 | + drawLine(True) if d in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False) |
| 31 | + tl.left(180) |
| 32 | + tl.penup() |
| 33 | + tl.fd(20) |
| 34 | + |
| 35 | +def drawDate(date): |
| 36 | + tl.pencolor("#AB82FF") |
| 37 | + for i in date: #根据设置的符号分隔年月日 |
| 38 | + if i == '-': |
| 39 | + tl.write('年',font=("Arial", 22, "normal")) |
| 40 | + tl.pencolor("#B3EE3A") |
| 41 | + tl.fd(40) |
| 42 | + elif i == '=': |
| 43 | + tl.write('月',font=("Arial", 22, "normal")) |
| 44 | + tl.pencolor("#FFD700") |
| 45 | + tl.fd(40) |
| 46 | + elif i == '+': |
| 47 | + tl.write('日',font=("Arial", 22, "normal")) |
| 48 | + else: |
| 49 | + drawDigit(eval(i)) |
| 50 | +def all(day): |
| 51 | + tl.goto(-350,-300) |
| 52 | + tl.pencolor("SlateBlue") |
| 53 | + tl.write('总共',font=("Arial", 40, "normal")) |
| 54 | + tl.fd(110) |
| 55 | + for j in day: |
| 56 | + drawDigit(eval(j)) |
| 57 | + tl.write('天',font=("Arial", 40, "normal")) |
| 58 | + |
| 59 | +def count(t1, t2, t3): |
| 60 | + t = t1*365 |
| 61 | + if t2 in [1, 2]: |
| 62 | + t += t2*30 |
| 63 | + if t2 in [3]: |
| 64 | + t = t+91 |
| 65 | + if t2 == 4: |
| 66 | + t += 122 |
| 67 | + if t2 == 5: |
| 68 | + t += 152 |
| 69 | + if t2 == 6: |
| 70 | + t += 183 |
| 71 | + if t2 == 7: |
| 72 | + t += 213 |
| 73 | + if t2 == 8: |
| 74 | + t += 244 |
| 75 | + if t2 == 9: |
| 76 | + t += 275 |
| 77 | + if t2 == 10: |
| 78 | + t += 303 |
| 79 | + if t2 == 11: |
| 80 | + t += 334 |
| 81 | + t += t3 |
| 82 | + return(str(t)) |
| 83 | + |
| 84 | +# 画出日期 |
| 85 | +def turtle_date(): |
| 86 | + tl.color('MediumTurquoise') |
| 87 | + tl.penup() |
| 88 | + tl.goto(-350,370) |
| 89 | + tl.pendown() |
| 90 | + # 获取到当前日期 |
| 91 | + tl.write('今天是:',font=("Arial", 22, "normal")) |
| 92 | + tl.pensize(5) |
| 93 | + tl.penup() |
| 94 | + tl.goto(-350,300) |
| 95 | + tl.pendown() |
| 96 | + drawDate(time.strftime('%Y-%m=%d+',time.gmtime())) |
| 97 | + tl.color('MediumTurquoise') |
| 98 | + tl.penup() |
| 99 | + tl.goto(-350,190) |
| 100 | + tl.pensize(1) |
| 101 | + tl.pendown() |
| 102 | + tl.pencolor("MediumTurquoise") |
| 103 | + tl.write('我加入 Python 团队的时间是:',font=("Arial", 22, "normal")) |
| 104 | + tl.penup() |
| 105 | + tl.goto(-350,110) |
| 106 | + tl.pendown() |
| 107 | + tl.pensize(5) |
| 108 | + # 加入团队的时间 |
| 109 | + drawDate('2019-09=03+') |
| 110 | + tl.penup() |
| 111 | + tl.goto(-350,0) |
| 112 | + tl.pensize(1) |
| 113 | + tl.pendown() |
| 114 | + tl.pencolor("MediumTurquoise") |
| 115 | + # 从加入日期到当前日期的月和天数 |
| 116 | + tl.write('我和团队成员一起经历了:',font=("Arial", 22, "normal")) |
| 117 | + tl.penup() |
| 118 | + tl.goto(0,-100) |
| 119 | + tl.pensize(1) |
| 120 | + tl.pendown() |
| 121 | + |
| 122 | +# 设置画笔 |
| 123 | +# def main(): |
| 124 | +# tl.setup(800, 350, 200, 200) #设置画布窗口大小以及位置 |
| 125 | +# tl.penup() |
| 126 | +# tl.fd(-350) |
| 127 | +# tl.pensize(5) |
| 128 | +# t = time.gmtime() #获取系统当前时间 |
| 129 | +# print(t) |
| 130 | +# drawDate(time.strftime('%Y-%m=%d+', t)) |
| 131 | +# tl.hideturtle() |
| 132 | +# tl.done() |
| 133 | + |
| 134 | +def main(): |
| 135 | + tl.setup(1000, 1000, 200, 200) |
| 136 | + turtle_date() |
| 137 | + tl.penup() |
| 138 | + tl.fd(-350) |
| 139 | + tl.pensize(5) |
| 140 | +# drawDate('2018-10=10+') |
| 141 | + t1 = time.gmtime() |
| 142 | + t2 = t1.tm_year-2019 |
| 143 | + t3 = t1.tm_mon-9 |
| 144 | + if t3<0: |
| 145 | + t2 -= 1 |
| 146 | + t3 += 12 |
| 147 | + t4 = t1.tm_mday-3 |
| 148 | + if t4 < 0: |
| 149 | + t3 -= 1 |
| 150 | + if t1.tm_mon-1 in [1, 3, 5, 7, 8, 10, 12]: |
| 151 | + t4 += 31 |
| 152 | + else: |
| 153 | + t4+=30 |
| 154 | + tatol = count(t2,t3,t4) |
| 155 | + drawDate(str(t2)+'-'+str(t3)+'='+str(t4)+'+') |
| 156 | + all(tatol) |
| 157 | + |
| 158 | + # 隐藏画笔 |
| 159 | + tl.hideturtle() |
| 160 | + |
| 161 | + # 落笔 |
| 162 | + tl.done() |
| 163 | + |
| 164 | + |
| 165 | +if __name__ == '__main__': |
| 166 | + main() |
| 167 | + |
| 168 | + |
| 169 | + |
0 commit comments