Last active
December 10, 2016 07:13
-
-
Save creationix/621ce40c56f02b8303d5fb66424fbd6c to your computer and use it in GitHub Desktop.
Sample bright-lang program with JS-style syntax. Easier on my son who recently learned JS.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
length = 60 // Our strip has 60 LEDs | |
bpp = 3 // We are using normal ws2812b lights that expect 3 bytes of color. | |
delay = 33 // Delay between animation loops in ms (defaults to 100) | |
sprites = 4 // Total number of sprites to spawn at startup | |
fizz = 3 // How many sprites to update per animation loop (defaults to all) | |
// This is called once per animation loop before updating sprites. | |
loop { | |
fade(20) | |
} | |
// This is called for each sprite when it's spawned. | |
// Variables created here are local to the sprite. | |
spawn { | |
p:length = rand // Random starting position | |
h:768 = rand // Random starting hue | |
l = rand(50) + 50 // Semi-random lifetime | |
} | |
// This is called once per sprite update | |
// you can access global variables as well as sprite local variables. | |
update { | |
p += 1 // Move 1 pixel forward | |
h += 7 // Slightly change hue | |
hue(p, h, 100) // Draw new position | |
l -= 1 // Decrement lifetime. | |
if l <= 0 { | |
explode // When lifetime reaches zero, explode! | |
} | |
} | |
// draw gradient that color shifts while fading away. | |
explode { | |
b = 255 | |
loop i:14 { | |
b -= 18 | |
hue(p + i, h, b) | |
hue(p - i, h, b) | |
} | |
respawn // And then restart the sprite. | |
} |
What kind of gear do I need to run this?
Thanks for sharing. This is so nice!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Function scope is very different than JS and much simpler.
Variables are all integers.