Лабораторные работы по Python, ЛФИ, 1 семестр
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.
|
|
|
import turtle as t
|
|
|
|
import typing
|
|
|
|
import math
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
|
|
# Put a list of coordinates (x, y) (where x from 0 to 1, y from 0 to 2) in the JSON file
|
|
|
|
DATA: typing.Dict[str, typing.List[typing.Tuple[int, int]]] = json.loads(open('font.json').read())
|
|
|
|
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)
|
|
|
|
|