出售本站【域名】【外链】

七段数码管26字母对照表(附带映射表以及映射数组)

好的,我可以帮你真现那个罪能。咱们可以运用之前界说的 `digit_layouts` 字典来绘制七段数码管字母斗劲表,而后再输出你的姓名。 ```python import turtle # 界说画笔 pen = turtle.Turtle() pen.speed(0) pen.hideturtle() # 界说绘制一个线段的函数 def draw_line(length, is_ZZZertical): pen.right(90 if is_ZZZertical else 0) pen.forward(length) pen.left(180 if is_ZZZertical else 90) pen.forward(length) pen.right(180 if is_ZZZertical else 90) pen.forward(length) pen.left(180 if is_ZZZertical else 90) pen.forward(length) pen.right(90 if is_ZZZertical else 0) # 界说绘制七段数码管的函数 def draw_digit_layout(layout, size): # 绘制第一条线段 if layout[0]: draw_line(size, False) pen.penup() pen.forward(size) pen.pendown() # 绘制第二条线段 if layout[1]: draw_line(size, False) pen.penup() pen.backward(size) pen.right(90) pen.forward(size) pen.left(90) pen.pendown() # 绘制第三条线段 if layout[2]: draw_line(size, True) pen.penup() pen.backward(size) pen.left(90) pen.forward(size * 2) pen.right(90) pen.pendown() # 绘制第四条线段 if layout[3]: draw_line(size, True) pen.penup() pen.backward(size) pen.right(90) pen.forward(size) pen.left(90) pen.pendown() # 绘制第五条线段 if layout[4]: draw_line(size, False) pen.penup() pen.forward(size) pen.pendown() # 绘制第六条线段 if layout[5]: draw_line(size, True) pen.penup() pen.backward(size) pen.left(90) pen.forward(size * 2) pen.right(90) pen.pendown() # 绘制第七条线段 if layout[6]: draw_line(size, True) pen.penup() pen.backward(size) pen.right(90) pen.forward(size) pen.left(90) # 界说绘制一个数字或字母的函数 def draw_digit(digit, size): layout = digit_layouts[digit] draw_digit_layout(layout, size) # 绘制七段数码管字母斗劲表 size = 30 pen.penup() pen.goto(-300, 200) pen.pendown() for i, digit in enumerate(digit_layouts.keys()): draw_digit(digit, size) pen.penup() pen.forward(size * 2) pen.pendown() if (i + 1) % 4 == 0: pen.penup() pen.goto(-300, pen.ycor() - size * 4) pen.pendown() # 输出姓名 pen.penup() pen.goto(-200, -200) pen.pendown() name = 'Your Name' for char in name: draw_digit(char.upper(), size) pen.penup() pen.forward(size * 2) pen.pendown() ``` 那样,你就可以看到绘制好的七段数码管字母斗劲表和输出的你的姓名了。假如须要批改字母大小和位置,可以调解 `size` 和 `pen.goto()` 函数的参数。


2025-01-01 10:36  阅读量:7