150,000 LEDs you can program. It starts with a clock that has moving hands. Pick another program, draw on the LEDs, or write your own code below.
This is the code of the program that is running. Change anything and press RUN MY CODE (or Ctrl + Enter). Nothing you do here can break the page: if the code has a mistake, the red box tells you the line.
Your program is a function called frame. It runs about 60 times a second and draws the next picture. Every pixel you draw is one LED. The grid is 500 LEDs across (x = 0 to 499, left to right) and 300 down (y = 0 to 299, top to bottom).
// a red dot that moves across the grid
function frame(g, t, now, api) {
api.clear('#000'); // all LEDs off
const x = (t * 100) % 500; // t = seconds since start
g.fillStyle = 'red';
g.fillRect(x, 140, 20, 20); // a 20 x 20 block of LEDs
api.text('HI WAYNE', 250, 40, 5, '#ffd23f', 'center');
}
| g | The drawing pen. It is a normal HTML canvas, so g.fillRect, g.arc, g.lineTo, g.strokeStyle and gradients all work. |
| t | Seconds since the program started (for animation). |
| now | The current date and time (a JavaScript Date): now.getHours(), now.getMinutes()… |
| api.clear(color) | Fill every LED with one color (black = off). |
| api.led(x, y, color) | Turn on one LED. |
| api.text(str, x, y, size, color, align) | Write in a classic 5 × 7 LED font. size 1 = 7 LEDs tall, 2 = 14 tall… align is 'left', 'center' or 'right'. Returns the width. |
| api.textWidth(str, size) | How many LEDs wide the text will be. |
| api.hsl(hue, sat, light) | A color from a hue (0 to 360). Handy for rainbows. |
| api.shade(fn, step) | Color every LED with a formula: fn(x, y) returns [red, green, blue] (0 to 255). step 2 does 2 × 2 blocks (faster). |
| api.buffer() | Direct access to all 150,000 LEDs: b.data holds red, green, blue, alpha for each one; call b.show() to put it on the grid. |
| api.rnd(a, b) | A random number from a to b. |
| api.message | The text in the MESSAGE box. |
| api.mouse | x, y and down of the mouse or finger on the grid. |
| W, H | 500 and 300. |
| function setup(g, api) | Optional. Runs once when the program starts. |
Anything you put outside frame (like let score = 0;) stays between frames. Save as my program keeps it in this browser; Download .js gives you a file to keep or share, and Open .js file loads one back.
500 × 300 = 150,000 LEDs, each one full color (16.7 million colors). Every LED is drawn as its own round (or square) dot, with dark "off" LEDs showing between the lit ones, like a real LED sign. On a big 4K screen each LED gets about 7 screen pixels; on a small screen the dots blend together, so use FULL SCREEN to see them best. LED COLOR turns it into a one-color sign (red, amber, green, blue or white), like the classic ones.