Canvas2DMX

๐Ÿš€ Getting Started with Canvas2DMX

Canvas2DMX lets you map pixels from your Processing sketch directly to DMX fixtures in real-time.
This quickstart will guide you through installation and your first test sketch.


1. Requirements


2. Installation

  1. Install the DMX4Artists library in Processing:
    • Open Processing โ†’ Sketch โ†’ Import Library โ†’ Add Libraryโ€ฆ
    • Search for DMX4Artists and install.
  2. Download or clone the Canvas2DMX library:
    git clone https://github.com/jshaw/Canvas2DMX.git
    
  3. Copy the built library folder into your Processing libraries directory:

    Documents/Processing/libraries/
    
  4. Restart Processing. You should now see Canvas2DMX listed under Sketch โ†’ Import Library.

3. Your First Sketch

Create a new Processing sketch and paste the following code:

import com.studiojordanshaw.canvas2dmx.*;
import com.jaysonh.dmx4artists.*;

Canvas2DMX c2d;
DMXControl dmxController;

void settings() {
  size(200, 200);
  pixelDensity(1);
}

void setup() {
  c2d = new Canvas2DMX(this);
  // Map one LED at the center
  c2d.setLed(0, width/2, height/2);
}

void draw() {
  // Animate background color
  background(frameCount % 255, 100, 200);

  // Get LED colors (samples canvas)
  int[] colors = c2d.getLedColors();

  // Visualize in a small swatch
  c2d.visualize(colors);

  // Show LED marker
  c2d.showLedLocations();
  
  // Send to DMX only if controller is connected
  if (dmxController != null) {
    c2d.sendToDmx((ch, val) -> dmxController.sendValue(ch, val));
  }
}

Run the sketch โ€” youโ€™ll see LED markers drawn over your canvas, with sampled colors shown in a visualization strip at the bottom.



4. Configuration Methods

Canvas2DMX provides several methods to configure how colors are sampled and sent to DMX:

Canvas Size (Off-Screen Buffers)

c2d.setCanvasSize(int width, int height);

Set custom canvas dimensions for LED mapping. Use this when sampling from a PGraphics buffer that has different dimensions than your sketch window. By default, Canvas2DMX uses the sketchโ€™s width and height.

Channel Pattern

c2d.setChannelPattern("drgb");  // dimmer + RGB
c2d.setChannelPattern("rgb");   // just RGB (default)
c2d.setChannelPattern("rgbw");  // RGB + white

Default Values

c2d.setDefaultValue('d', 255);  // dimmer at full
c2d.setDefaultValue('s', 0);    // strobe off

Response Curve

c2d.setResponse(2.2);           // gamma correction
c2d.setTemperature(-0.3);       // warm color shift

5. Working with Off-Screen Buffers

For advanced workflows, you can sample from a PGraphics buffer instead of the main canvas. This is useful when you want to keep LED mapping resolution independent from display resolution.

import com.studiojordanshaw.canvas2dmx.*;

Canvas2DMX c2d;
PGraphics ledBuffer;

void setup() {
  size(800, 600);
  
  // Create a smaller buffer for LED sampling
  ledBuffer = createGraphics(100, 100);
  
  c2d = new Canvas2DMX(this);
  
  // IMPORTANT: Tell Canvas2DMX the buffer dimensions
  c2d.setCanvasSize(100, 100);
  
  // Map LEDs relative to buffer coordinates
  c2d.mapLedStrip(0, 10, 50, 50, 8, 0, false);
}

void draw() {
  // Draw to the off-screen buffer
  ledBuffer.beginDraw();
  ledBuffer.background(0);
  ledBuffer.fill(255, 100, 0);
  ledBuffer.ellipse(
    map(mouseX, 0, width, 0, 100),
    map(mouseY, 0, height, 0, 100),
    30, 30
  );
  ledBuffer.endDraw();
  
  // Display buffer scaled up to window
  image(ledBuffer, 0, 0, width, height);
  
  // Sample from the buffer's pixels
  ledBuffer.loadPixels();
  int[] colors = c2d.getLedColors(ledBuffer.pixels);
  
  c2d.visualize(colors);
}

Key Points


4. Next Steps


โœ… Thatโ€™s it! Youโ€™re ready to build interactive Processing sketches that control DMX lighting in real time.


๐Ÿ“š Learn More


๐Ÿ“œ License

MIT License ยฉ 2025 Studio Jordan Shaw