This is a loose collection of example scripts for pyghthouse.
Run any script by entering python <filename>.
Some scripts have additional dependencies; Check README.md in the repository root directory for an installation guide
If you set up config.py with your username and API token, you won't have to enter them every time you run a script. Be aware that API tokens are only valid for a few days.
The Pyghthouse library has two intended ways of usage:
-
Passing a callback function at creation with
Pyghthouse(..., callback=function)or with the methodPyghthouse.set_image_callback(callback) -
Setting the currently shown canvas with
Pyghthouse.set_image()
The following examples uses callback functions:
huecircle.pynoisefill.pyrainbow.pyrgbfill.pyrgbscan.pytwopoints.py
In summary, we first need a callback function to create images when called. After that, we initialize the pyghthouse routine.
When we now start the pyghthouse routine, images will be generated by the given callback function. Generated images are then send to the server. This will happen in an interval given by the frame_rate.
The pyghthouse routine is now running asynchronous to the main script.
Important to notice is, that the pyghthouse routine will end when the main script ends. To let a pyghthouse routine run forever (until error or keyboard interrupt), the keep_running() method can be used.
The following examples use set_image:
movingdot.pywhitefill.py
Compared to the callback function, set_image is a lot simpler.
We again need to initialize and start the pyghthouse routine. After that, we only need to call set_image(new_image) to send images to the server.
Important to notice is, that set_imagedoes not wait until the image is send. This means that we can overwrite the currently set image by setting a new one without waiting for the send. So to ensure important frames to be send, we recommend to use the method wait().
-
Pyghthouse(username: str, token: str, ...):Set up the
Pyghthouseobject. Needed arguments areusernameandtoken. Optional arguments, likeframe_rateand further explanations can be found in the class definition (seepyghthouse\ph.py) -
Pyghthouse.start()Starts the pyghthouse routine and opens the websocket connection.
-
Pyghthouse.stop()Stops the pyghthouse routine and closes the websocket connection.
-
Pyghthouse.empty_image()A static method which creates a black image. This function can also be called with an instance of the
Pyghthouseobject (<instance name>.empty_image()) -
Pyghthouse.set_image(image)Set the Pyghthouse canvas to
image. Every1/frame_rateseconds, the last image set is send by the pyghthouse routine.
More functions can be found in pyghthouse\ph.py
Here are additional functions in the pyghthouse package.
-
pyghthouse.utils.from_html(html_color):Converts an HTML color string like FF7F00 or #c0ffee to RGB
-
pyghthouse.utils.from_hsv(h: float, s: float, v: float):Converts HSV (float values between 0 and 1) colors to RGB.