-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.py
executable file
·56 lines (44 loc) · 1.31 KB
/
graph.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
#! /usr/bin/env python3
import time
import requests
import unicornhat as unicorn
RED = [203, 42, 40]
GREEN = [0, 102, 51]
BLUE = [76, 142, 204]
YELLOW = [246, 176, 78]
def get_player_count():
try:
r = requests.get(
"https://crossbow.feud.bearwaves.com:1323/status/playersOnline"
)
if r.status_code != 200:
r.raise_for_error()
return r.json()['playersOnline'], True
except Exception:
return 0, False
def set_colour(x, y, colour):
unicorn.set_pixel(x, y, colour[0], colour[1], colour[2])
def draw_graph(graph):
for j in range(len(graph)):
for i in range(len(graph[j])):
set_colour(j, i, graph[j][i])
def draw_column(count, column):
for i in range(count):
column[6-(i % 7)] = [BLUE, YELLOW][i//7]
try:
unicorn.brightness(0.5)
unicorn.rotation(180)
graph = [[[0 for k in range(3)] for j in range(8)] for i in range(8)]
while True:
graph = graph[1:8] + [[[0 for k in range(3)] for j in range(8)]]
count, success = get_player_count()
if not success:
graph[7][7] = RED
else:
graph[7][7] = GREEN
draw_column(count, graph[7])
draw_graph(graph)
unicorn.show()
time.sleep(5)
except KeyboardInterrupt:
unicorn.off()