You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
1.5 KiB
48 lines
1.5 KiB
import turtle as t |
|
import typing |
|
import math |
|
|
|
|
|
DATA: typing.Dict[str, typing.List[typing.Tuple[int, int]]] = { |
|
'0': [(0, 0), (1, 0), (1, 1), (1, 2), (0, 2), (0, 1), (0, 0)], |
|
'1': [(0, 1), (1, 0), (1, 1), (1, 2)], |
|
'2': [(0, 0), (1, 0), (1, 1), (0, 2), (1, 2)], |
|
'3': [(0, 0), (1, 0), (0, 1), (1, 1), (0, 2)], |
|
'4': [(0, 0), (0, 1), (1, 1), (1, 0), (1, 2)], |
|
'5': [(1, 0), (0, 0), (0, 1), (1, 1), (1, 2), (0, 2)], |
|
'6': [(1, 0), (0, 1), (1, 1), (1, 2), (0, 2), (0, 1)], |
|
'7': [(0, 0), (1, 0), (0, 1), (0, 2)], |
|
'8': [(0, 0), (1, 0), (1, 1), (0, 1), (0, 2), (1, 2), (1, 1), (0, 1), (0, 0)], |
|
'9': [(0, 0), (1, 0), (1, 1), (0, 2), (1, 1), (0, 1), (0, 0)] |
|
} |
|
DIGIT_SIZE = 25 |
|
|
|
|
|
def go_delta(delta_x: int, delta_y: int, coef=DIGIT_SIZE): |
|
t.seth(math.degrees(math.atan2(-delta_y, delta_x))) |
|
t.forward(math.hypot(delta_x, delta_y) * coef) |
|
|
|
|
|
def write_coordinates(data: typing.List[typing.Tuple[int, int]]): |
|
t.penup() |
|
go_delta(*data[0]) |
|
t.pendown() |
|
for previous_point, next_point in zip(data, data[1:]): |
|
go_delta(next_point[0] - previous_point[0], next_point[1] - previous_point[1]) |
|
t.penup() |
|
go_delta(-data[-1][0], -data[-1][1]) |
|
|
|
|
|
def write_digit(num: typing.Union[int, str]): |
|
num: str = str(num) |
|
data: typing.List[typing.Tuple[int, int]] = DATA.get(num) |
|
write_coordinates(data) |
|
go_delta(1.5, 0) |
|
|
|
|
|
if __name__ == '__main__': |
|
numbers = input('Numbers: ') |
|
t.shape('turtle') |
|
for digit in numbers: |
|
write_digit(digit) |
|
|
|
|