200 big LEDs you can program (there is also a 500 × 300 version). 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 20 LEDs across (x = 0 to 19, left to right) and 10 down (y = 0 to 9, top to bottom).
// a red LED that walks across, and the minutes in small numbers
function frame(g, t, now, api) {
api.clear('#000'); // all LEDs off
const x = Math.floor(t * 4) % 20; // t = seconds since start
api.led(x, 9, 'red'); // one LED on the bottom row
api.small(String(now.getMinutes()), 0, 0, '#ffd23f');
api.line(19, 0, 12, 7, '#3fa7ff'); // a straight line of LEDs
}
| 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.line(x1, y1, x2, y2, color) | A straight line of LEDs from one LED to another. |
| api.small(str, x, y, color, align) | Write in a small 3 × 5 font (numbers, letters, colon). Each letter is 3 LEDs wide, so 5 fit across. Returns the width. |
| api.text(str, x, y, size, color, align) | Write in the classic 5 × 7 LED font (size 1 = 7 LEDs tall; 3 letters fit across). Good for scrolling. 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 200 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 | 20 and 10. |
| 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.
20 × 10 = 200 LEDs, each one full color (16.7 million colors). Every LED is drawn as its own big round (or square) bulb, with dark "off" LEDs showing between the lit ones, like a real LED sign or scoreboard. With only 10 rows, the clock face is 9 × 9 LEDs and numbers use a small 3 × 5 font; longer words scroll. LED COLOR turns it into a one-color sign (red, amber, green, blue or white), like the classic ones.