Skip to content

Commit a52598a

Browse files
author
Gedusim
committed
New example for local package usage
1 parent b4b917b commit a52598a

File tree

1 file changed

+66
-0
lines changed

1 file changed

+66
-0
lines changed

example.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
'''
2+
This example should give a simple overview on how to use the Pyghthouse.
3+
4+
A generel orientation of what you need:
5+
- Import of pyghthouse
6+
- Creating an instance of Pyghthouse
7+
- start connection
8+
- Sending images with either a given function or set_image(image)
9+
- close connection (not needed but recommend)
10+
11+
More examples can be found in the examples folder.
12+
13+
Note that this skript handles Pyghthouse as a local module compared to
14+
the skripts in examples; These handle Pyghthouse as an installed package.
15+
Check examples/README.md for more informations.
16+
'''
17+
18+
from pyghthouse import Pyghthouse
19+
import pyghthouse.utils as utils
20+
from examples.config import UNAME, TOKEN
21+
22+
# Optional: This condition only executes if run as a skript.
23+
# Importing this program won't execute this block.
24+
if __name__ == '__main__':
25+
26+
# Create instance of Pyghthouse and start connection
27+
username = UNAME
28+
token = TOKEN
29+
p = Pyghthouse(username, token)
30+
p.start()
31+
32+
# the image is a 3 dimensional list, meaning a list with [[[r,g,b]]] entries
33+
# create a black image
34+
img = p.empty_image()
35+
36+
pos_x = 10
37+
pos_y = 5
38+
# color entries are in rgb
39+
color = [100, 124, 24]
40+
41+
# sends the given image
42+
img[pos_y][pos_x] = color
43+
p.set_image(img)
44+
45+
key = input("Enter 'n' for the next image, enter any other key to skip\n")
46+
if key.upper() == "N":
47+
# set rgb color with a converted hsv color
48+
color = utils.from_hsv(0.5, 1.0, 0.7)
49+
50+
# set all pixels to the current color
51+
for x in range(28):
52+
for y in range(14):
53+
img[y][x] = color
54+
p.set_image(img)
55+
56+
key = input("Enter 'n' for the next image, enter any other key to skip\n")
57+
if key.upper() == "N":
58+
color = [255, 255, 255]
59+
60+
# create 3 white lines
61+
for x in range(28):
62+
for y in range(3,10,3):
63+
img[y][x] = color
64+
p.set_image(img)
65+
66+
p.close()

0 commit comments

Comments
 (0)