-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFruitGenerator.py
More file actions
30 lines (28 loc) · 872 Bytes
/
Copy pathFruitGenerator.py
File metadata and controls
30 lines (28 loc) · 872 Bytes
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
import threading
from random import randint
import sys
import tty
import time
import unicornhat as unicorn
unicorn.brightness(.5)
unicorn.set_layout(unicorn.AUTO)
unicorn.rotation(0)
width,height=unicorn.get_shape()
unicorn.rotation(0)
class fruitGenerator(threading.Thread):
def __init__(self,observer):
self.observer = observer;
threading.Thread.__init__(self);
self.greenApple=[128,255,0];
self.redApple=[255,102,102];
self.basket=[self.greenApple,self.redApple];
# self.fruit = [];
def run(self):
while not self.observer.exit:
if len(self.observer.fruitBasket) < 4:
fruit=[randint(0,width-1),randint(0,height-1),self.basket[randint(0,1)]];
self.observer.addFruit(fruit);
time.sleep(5);
def draw(self):
for i in self.observer.fruitBasket:
unicorn.set_pixel(i[0],i[1],i[2][0],i[2][1],i[2][2]);