forked from Musicted/pyghthouse
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexample.py
More file actions
77 lines (55 loc) · 2.29 KB
/
Copy pathexample.py
File metadata and controls
77 lines (55 loc) · 2.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
'''
This example should give a simple overview on how to use Pyghthouse.
A generel orientation of what you need:
- Import of pyghthouse
- Creating an instance of Pyghthouse
- Start Pyghthouse routine
- Sending images with either a given callback function or by set_image
- Stop Pyghthouse routine (not needed but recommended)
More examples can be found in the examples folder.
'''
# Optional: This condition only executes if run as a script.
# Importing this program won't execute this block.
if __name__ == '__main__':
from pyghthouse import Pyghthouse
import pyghthouse.utils as utils
from examples.config import UNAME, TOKEN
# Create instance of Pyghthouse and start Pyghthouse routine
username = UNAME
token = TOKEN
p = Pyghthouse(username, token)
p.start()
# The image object is a 3 dimensional list. Each index is accessed via [row][collum][rgb]
# Create a black image
img = p.empty_image()
pos_x = 10
pos_y = 5
# The used color is in the RGB format. We use a list where each index represents a color channel.
# Index 0 for red, 1 for green, 2 for blue.
# Each color channel has a size of 1 byte, so values from 0 to 255 can be used.
color = [100, 124, 24]
# Set the image with one colored pixel
img[pos_y][pos_x] = color
p.set_image(img)
key = input("Enter 'n' for the next image, enter any other key to skip\n")
if key.upper() == "N":
# Our library also have convertors for other color formats.
# Now we convert a hsv color to an rgb color
color = utils.from_hsv(0.5, 1.0, 0.7)
# Set the color of all pixels
for y in range(14):
for x in range(28):
img[y][x] = color
p.set_image(img)
key = input("Enter 'n' for the next animation, enter any other key to skip\n")
if key.upper() == "N":
color = [255, 255, 255]
# Let 3 white lines appear
for x in range(28):
for y in range(3,10,3):
img[y][x] = color
p.set_image(img)
# set_image overwrites the old image. So to prevent the loss of an image,
# we wait until the frame has been build
p.wait()
p.stop()