LED GRID 80 × 40

3,200 LEDs you can program (also in 20 × 10 and 500 × 300). It starts with a clock that has moving hands. Pick another program, draw on the LEDs, or write your own code below.

PROGRAM
LED COLOR BRIGHTNESS LEDS
MESSAGE used by the Scrolling message program, and by your code as api.message

Program code

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.

How to program it

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 80 LEDs across (x = 0 to 79, left to right) and 40 down (y = 0 to 39, 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 * 10) % 80;      // t = seconds since start
  api.led(x, 39, 'red');                  // one LED on the bottom row
  api.text('HI WAYNE', 40, 10, 1, '#ffd23f', 'center');
  api.small(String(now.getMinutes()), 0, 0, '#ffd23f');
  api.line(79, 0, 60, 30, '#3fa7ff');     // a straight line of LEDs
}
gThe drawing pen. It is a normal HTML canvas, so g.fillRect, g.arc, g.lineTo, g.strokeStyle and gradients all work.
tSeconds since the program started (for animation).
nowThe 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 20 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, 13 letters across; size 2 = 14 tall; size 3 = 21 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 3,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.messageThe text in the MESSAGE box.
api.mousex, y and down of the mouse or finger on the grid.
W, H80 and 40.
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.

About the grid

80 × 40 = 3,200 LEDs, each one full color (16.7 million colors). Every LED is drawn as its own round (or square) bulb, with dark "off" LEDs showing between the lit ones, like a real LED sign. The clock face is 39 LEDs across; the classic 5 × 7 letters fit 13 across, the small 3 × 5 ones 20 across. LED COLOR turns it into a one-color sign (red, amber, green, blue or white), like the classic ones.