#1、数码管的绘制
#2、导入库模块
from turtle import *
from random import *
import time
#3、绘制单段间隔
def drawGap():
penup()
fd(5)
#4、绘制单段数码管
def drawLine(draw):
drawGap()
if draw:
pendown()
else:
penup()
fd(20)
drawGap()
right(90)
#5、根据数字绘制七段数码管
def drawDigit(digit):
pencolor(random(),random(),random())#随机获取0—1的颜色
drawLine(True) if digit in [2,3,4,5,6,8,9] else drawLine(False) #用第1段的数字
pencolor(random(),random(),random())
drawLine(True) if digit in [0,1,3,4,5,6,7,8,9] else drawLine(False) #用第2段的数字
pencolor(random(),random(),random())
drawLine(True) if digit in [0,2,3,5,6,8,9] else drawLine(False) #用第3段的数字
pencolor(random(),random(),random())
drawLine(True) if digit in [0,2,6,8] else drawLine(False) #用第4段的数字
left(90) #将画笔
Python——七段电子数码管的绘制
最新推荐文章于 2024-05-07 06:36:34 发布