#七段数码管的绘制.py
#导入库模块
from turtle import *
from random import *
#绘制单段间隔
def drawGap():
penup()
fd(5)
#绘制单段数码管
def drawLine(draw):
drawGap()
if draw:
pendown()
else:
penup()
fd(40)
drawGap()
right(90)
#根据数字绘制七段数码管
def drawDigit(digit):
pencolor(random(),random(),random())
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段的数字
pencolor(random(),random(),random())
left(90)
drawLine(True) if digit in [0,4,5,6,8,9] else drawLine(False) #用第5段的数字
pencolor(random(),random(),random())
drawLine(True) if digit in [
Python基础《七段数码管的绘制》
最新推荐文章于 2024-08-03 19:27:22 发布