Light Projects

A collection LED control examples for Arduino

Low-voltage DC Lamps
LED Strip Control
Addressable LEDs
Color Spaces
Pattern Making

This project is maintained by tigoe

Pattern Making With Code

For many lighting projects, you need to generate patterns. Two common uses for this would be to make lampshade or diffuser patterns. These can often be cut on aser cutters or vinyl cutters, mills or other CNC machines. To cut a pattern on one of these, you’ll likely need your pattern in a vector file. Most laser cutters will take an SVG file (scalable vector graphics), for example, and many vinyl cutters will take a DXF file (AutoCAD Drawing Interchange Format).

One way to do this is to generate your pattern in software using a graphics-friendly programming environment like Processing or p5.js, then output the pattern to an SVG or DXF file. The challenge is finding a graphics-friendly environment that can generate vector graphics.

Processing has two good libraries, one for generating SVGs and one for generating DXF files. Here’s an example of how to generate either file format from a very simple pattern. This Processing sketch will generate a new random pattern every two seconds, because the frameRate is set to 0.5. Here’s a slightly more complex example that uses a circle packing algorithm to generate 500 circles every time you press the S or D key, and saves the pattern as SVG or DXF.

p5.js doesn’t have a DXF library, but it does have most current SVG library for it has been updated to work with p5 version 1.3.1, though seems fine with 1.4.0 as well Here’s a version of the circle packing sketch done in p5.js. Reload the page if you don’t like the pattern. (here’s the code ).Because p5.js is based on Processing, their APIs are similar enough that it’s relatively easy to convert a pattern-making program from p5.js to Processing.

Rune Madsen’s rune.js is a pretty good tool for generating SVGs, and can be combined with p5.js as well.