Skip to content

Instantly share code, notes, and snippets.

@codecat
Last active May 24, 2023 19:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecat/98fe0ce7a79a00aac698f89869b6159f to your computer and use it in GitHub Desktop.
Save codecat/98fe0ce7a79a00aac698f89869b6159f to your computer and use it in GitHub Desktop.
Friendly Pixel Format for Twitch

Friendly Pixel Format

On my Twitch stream, you can type commands in chat to run custom lightshow code.

Community emulator

Community member yugecin26 has made a fairly accurate emulator for the light code described below. You can use it to test light code before putting it in chat!

Strip specifications

I have 2 LED strips with 180 RGB pixels each. They always run its animations at 30 FPS.

Changelog

2023-04-23

  • Added time range syntax: (#f00 +500ms-1s)
  • Added ability to have multiple animators per operator: (#f00 -> #0f0 -> #00f)
  • Added support for more than 2 colors in gradients: (#f00-#0f0-#00f)
  • Added support for beat-synchronized time durations: (#f00 ->1x #000)
  • Added support for decimals in time durations: (#f00 ->.2s #000)
  • Added ability to specify strip flags in statements: (:L #f00) (:R #00f)

Examples

Here's a few examples:

  • Fill entire strip:
    (#F00)
    
  • Fill entire strip with a gradient:
    (#F00-#0F0)
    
  • Fill entire strip with a gradient with multiple colors:
    (#F00-#0F0-#00F-#FF0-#0FF-#F0F)
    
  • Paint single pixel at offset 100:
    (@100, #F00)
    
  • Paint range of pixels:
    (@100-180, #F00)
    
  • Paint range of pixels with a gradient:
    (@100-180, #F00-#0F0)
    
  • Fade from red to blue pixels in 2 seconds in a range of pixels:
    (@100-180, #F00 ->2s #00F)
    
  • Fade from red to blue pixels in 2 seconds while also moving and resizing the pixel range for 1 second:
    (@100-180 -> @120-130, #F00 ->2s #00F)
    

Animations

Properties of a statement can be animated. The syntax for this is an arrow -> and can appear in statements multiple times. For example:

  • Animate from red to blue in 1 second:
    (#f00 -> #00f)
    
  • Animate from red to blue in 2.5 seconds:
    (#f00 ->2.5s #00f)
    
  • Animate from red to blue in 2 seconds after 3 seconds:
    (#f00 3s->2s #00f)
    
  • Flip a gradient over 5 seconds:
    (#f00-#00f ->5s #00f-#f00)
    
  • Move range of pixels over time
    (@0-90 -> @91-180)
    
  • Move range of red pixels back and forth
    (#f00 @100-120 ->500ms @20-40 ->500ms @100-120)
    

Multiple statements

You can chain multiple statements together. For example, you can fill 2 halves of all pixels like this:

(@0-90, #f00) (@90-180, #00f)

Time range

You can make a statement show up during a specific time range using the + operator. For example:

  • Flash the bottom red for 500ms, flash the top blue for 500ms:
    :loop (@0-90, #f00 +0ms-500ms) (@91-180, #00f +500ms)
    
  • Flash green red and blue stripes downwards at different times:
    :loop (@160-180 ->200ms @0-20, #f00 +0ms-200ms) (@160-180 ->200ms @0-20, #0f0 +200ms-400ms) (@160-180 ->200ms @0-20, #00f +400ms-600ms)
    

Time units

Any time in the syntax is formed from a decimal number (for example 1, .5, 2.5, or 500) and a unit. The following units are supported:

  • s Seconds
  • ms Milliseconds
  • x Beat multiplier: this is synchronized to the beat. For example, 1x is one beat long, .5x is half a beat, 2x is 2 beats

Code flags

You can also specify flags at the beginning of your command. For example, to specify the beat flag:

:beat (#fff ->300ms #000)

The available flags are:

  • beat Restart the light code on the beat.
  • loop Loop the light code.

Statement flags

Statements also have flags. Currently they only allow you to pick which LED strip is being rendered to. For example, to render the left strip red and the right strip blue:

(:L #f00) (:R #00f)

The available flags are l (same as L) and r (same as R).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment