1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
| import turtle import time import random
def drawLine(draw): turtle.pendown() if draw else turtle.penup() turtle.fd(70) turtle.right(90)
def drawDigit(digit,color): turtle.pencolor(color) drawLine(True) if digit in [2, 3, 4, 5, 6, 8, 9] else drawLine(False) drawLine(True) if digit in [0, 1, 3, 4, 5, 6, 7, 8, 9] else drawLine(False) drawLine(True) if digit in [0, 2, 3, 5, 6, 8, 9] else drawLine(False) drawLine(True) if digit in [0, 2, 6, 8] else drawLine(False) turtle.left(90) drawLine(True) if digit in [0, 4, 5, 6, 8, 9] else drawLine(False) drawLine(True) if digit in [0, 2, 3, 5, 6, 7, 8, 9] else drawLine(False) drawLine(True) if digit in [0, 1, 2, 3, 4, 7, 8, 9] else drawLine(False) turtle.penup() turtle.left(180) turtle.fd(-70) time.sleep(0.8) turtle.clear()
def randomColor(): num1 = random.random() num2 = random.random() num3 = random.random() return num1,num2,num3
def main(): turtle.setup(500,500) turtle.penup() turtle.fd(-25) turtle.pensize(5) turtle.speed(0.1) for i in range(1,11): drawDigit(10-i,randomColor()) turtle.write("邓恩熙1314",font=("Arial",55,"normal"),align="center") turtle.hideturtle() turtle.done()
main()
|