Skip to content

Latest commit

 

History

History
 
 

README.md

Pyghthouse Examples

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.

Ways of programming a pyghthouse script

The Pyghthouse library has two intended ways of usage:

  • Passing a callback function at creation with Pyghthouse(..., callback=function) or with the method Pyghthouse.set_image_callback(callback)

  • Setting the currently shown canvas with Pyghthouse.set_image()

Programming with callback

The following examples uses callback functions:

  • huecircle.py
  • noisefill.py
  • rainbow.py
  • rgbfill.py
  • rgbscan.py
  • twopoints.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.

Programming with set_image

The following examples use set_image:

  • movingdot.py
  • whitefill.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 package content

The class pyghthouse.Pyghthouse with

  • Pyghthouse(username: str, token: str, ...):

    Set up the Pyghthouse object. Needed arguments are username and token. Optional arguments, like frame_rate and further explanations can be found in the class definition (see pyghthouse\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 Pyghthouse object (<instance name>.empty_image())

  • Pyghthouse.set_image(image)

    Set the Pyghthouse canvas to image. Every 1/frame_rate seconds, the last image set is send by the pyghthouse routine.

More functions can be found in pyghthouse\ph.py

Utils functions

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.