This repository has been 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
/
vexbot.py
92 lines (58 loc) · 1.68 KB
/
vexbot.py
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
87
88
89
90
91
92
import requests
import json
from os import system
from math import sqrt
width = 100
height = 40
# gets a specified amount of lines
def get_lines(num_lines, connected=0):
if num_lines <= 0 : num_lines = 1
if num_lines > 1000 : num_lines = 1000
connected = int(connected)
request = requests.get(f'https://api.noopschallenge.com/vexbot?count={num_lines}&width={width}&height={height}&connected=0')
points = json.loads(request.content)["vectors"]
return points
# clears console
def clear():
system('cls')
# draws screen
def draw(pos, lines):
screen = ''
for i in range(height):
screen += '\n'
for j in range(width):
if [j, i] in pos:
screen += 'o'
elif [j, i] in lines:
screen += '+'
else:
screen += ' '
print(screen)
# create lines
points = get_lines(5)
# work out the positions of points and lines
pos = []
lines = []
for point in points:
x1, y1 = point["a"]["x"], point["a"]["y"]
x2, y2 = point["b"]["x"], point["b"]["y"]
dvelx = x2 - x1
dvely = y2 - y1
mag = sqrt((dvelx**2) + (dvely**2))
normalx = dvelx / mag
normaly = dvely / mag
x, y = x1, y1
while True:
if int(x) != x2:
x += normalx
if int(y) != y2:
y += normaly
if int(x) == x2 and int(y) == y2:
break
if [int(x), int(y)] not in lines:
lines.append([int(x), int(y)])
pos.append([x1, y1])
pos.append([x2, y2])
# clear and draw the screen
clear()
draw(pos, lines)