-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc_tree.py
More file actions
65 lines (51 loc) · 1.37 KB
/
c_tree.py
File metadata and controls
65 lines (51 loc) · 1.37 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
import threading
import random
import os
import time
mutex = threading.Lock()
tree = list(open("tree2.txt").read().rstrip())
def colored_dot(color):
if color == "red":
return f"\033[91m☆\033[0m"
if color == "green":
return f"\033[92m☆\033[0m"
if color == "yellow":
return f"\033[93m☆\033[0m"
if color == "blue":
return f"\033[94m☆\033[0m"
def lights(color, indexes):
off = True
while True:
for idx in indexes:
tree[idx] = colored_dot(color) if off else "☆"
mutex.acquire()
os.system("cls" if os.name == "nt" else "clear")
print("".join(tree))
mutex.release()
off = not off
time.sleep(random.uniform(0.5, 1.5))
yellow = []
red = []
green = []
blue = []
for i, c in enumerate(tree):
if c == "Y":
yellow.append(i)
tree[i] = "☆"
if c == "R":
red.append(i)
tree[i] = "☆"
if c == "G":
green.append(i)
tree[i] = "☆"
if c == "B":
blue.append(i)
tree[i] = "☆"
ty = threading.Thread(target=lights, args=("yellow", yellow))
tr = threading.Thread(target=lights, args=("red", red))
tg = threading.Thread(target=lights, args=("green", green))
tb = threading.Thread(target=lights, args=("blue", blue))
for t in [ty, tr, tg, tb]:
t.start()
for t in [ty, tr, tg, tb]:
t.join()