Skip to main content

Python tools for the Radiance video art system

Project description

Radiance provides a simple way to output to light displays. A python library is provided for easy implementation on your device or middleware. All you have to do is instantiate a LightOutputNode and point it to your device.

Example device

To try it out, run it in the background. Then, open Radiance and create a new LightOutputNode pointing at localhost. Add a full-screen pattern such as purple before the LightOutputNode to fill the display with color. You should see a circle of lights that correspond to the edges of the frame.

If you restart the server and want to reconnect, simply select the LightOutputNode and hit R.

#!/usr/bin/env python3

import logging
import math
import radiance

# This example shows how to interface custom hardware to radiance.

# This basic idea here is to subclasses radiance.LightOutputNode
# and override callback methods in it
# with custom functionality.

class Example(radiance.LightOutputNode):
    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

        # This tells Radiance the name of our device, and how big the sampled canvas should be.
        self.description = {
            "name": "Python Example",
            "size": [100, 100]
        }

        # This would request 5 pixels at the corners and center.
        #self.lookup_2d([(0, 0), (0, 1), (1, 0), (1, 1), (0.5, 0.5)])

        # Instead, lets request 120 pixels around the border.
        N = 30
        self.lookup_2d = [(0, i / N) for i in range(N)]
        self.lookup_2d += [(i / N, 0) for i in range(N)]
        self.lookup_2d += [(1, 1 - i / N) for i in range(N)]
        self.lookup_2d += [(1 - i / N, 1) for i in range(N)]

        # If we stopped here, Radiance would visualize this display using the lookup coordinates
        # and show a square.
        # If the physical display looks different, we tell Radiance about it with the
        # "physical coordinates" command.
        # Lets tell Radiance to visualize the points as a circle instead.

        def moveToCircle(x, y):
            l = math.hypot(x - 0.5, y - 0.5)
            return (0.5 * (x - 0.5) / l + 0.5, 0.5 * (y - 0.5) / l + 0.5)
        self.physical_2d = [moveToCircle(x, y) for (x, y) in self.lookup_2d]

        # We can send radiance a PNG file to be used as a background image for visualization.
        # This logo image is not very useful, but perhaps some line-art of your venue would work well.

        #with open("../resources/library/images/logo.png", "rb") as f:
        #    self.geometry_2d = f.read()

        # Ask for frames from Radiance every 20 ms (50 FPS).
        # On flaky connections, set this to zero.
        # Doing so will request frames one-by-one in a synchronous manner,
        # which will avoid network congestion.
        self.period = 20

    # This gets called every time a frame is received.
    def on_frame(self, frame):
        # This is where you would output to LED strips
        # or whatever hardware you have.

        # For now, lets just print out the RGB values for the first few pixels
        # to the console.
        # Print the RGB values for the first few pixels to the console
        print(frame[0:5])

# Turn on logging so we can see debug messages
logging.basicConfig(level=logging.DEBUG)

# Construct our device
device = Example()

# Start it going
device.serve_forever()

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

radiance-0.1dev5.tar.gz (3.4 kB view details)

Uploaded Source

File details

Details for the file radiance-0.1dev5.tar.gz.

File metadata

  • Download URL: radiance-0.1dev5.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Python-urllib/3.7

File hashes

Hashes for radiance-0.1dev5.tar.gz
Algorithm Hash digest
SHA256 870d0076f8c4da1803aa3798039a86c65b683c04d722dcd259dffb63176dc0e6
MD5 ed9c5dacc1459f53bf323013b1aada36
BLAKE2b-256 fc663f3e2ec1d26b04d0bd0355b02456020f2ba0f1eb13ea69754b5fe7edb88b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page