Lev
3 years ago
2 changed files with 57 additions and 0 deletions
@ -0,0 +1,9 @@
|
||||
from random import randint, random, uniform |
||||
import turtle as t |
||||
|
||||
|
||||
t.shape('turtle') |
||||
while True: |
||||
t.right(uniform(-120, 120)) |
||||
t.forward(uniform(0, 50)) |
||||
|
@ -0,0 +1,48 @@
|
||||
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) |
||||
|
Loading…
Reference in new issue