This repository was archived by the owner on May 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpolybot.py
More file actions
86 lines (46 loc) · 1.29 KB
/
polybot.py
File metadata and controls
86 lines (46 loc) · 1.29 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import requests
import json
from os import system
from math import sqrt
def clear():
system('cls')
def get_shape():
req = requests.get(f'https://api.noopschallenge.com/polybot?count=1&width={width}&height={height}')
points = []
shape = json.loads(req.content)["polygons"]
for i in shape[0]:
points.append([i["x"], i["y"]])
return points
def draw(points, lines):
clear()
screen = ''
for i in range(height):
screen += '\n'
for j in range(width):
if [j, i] in points:
screen += 'O'
elif [j, i] in lines:
screen += '+'
else:
screen += ' '
print(screen)
width = 50
height = 40
shape = get_shape()
lines = []
for x1, y1 in shape:
for x2, y2 in shape:
dx = x2 - x1
dy = y2 - y1
mag = sqrt(dx**2 + dy**2)
if mag != 0:
vec = [dx / mag, dy / mag]
else:
vec = [0, 0]
while int(x1) != x2 and int(y1) != y2:
x1 += vec[0]
y1 += vec[1]
if [int(x1), int(y1)] not in lines:
lines.append([int(x1), int(y1)])
draw(shape, lines)
print(shape)