Hi! Let me first narrate your code. For the sake of understanding it, I think you’re using number[]
as synonymous with sparks[]
.
export var number = array(vals)
number[0] = 5
Create a new array with ‘vals’ number of elements. Since we’ll use it in render in a sec, we want to be sure vals is at least as big as our strip, so it should maybe be var number array(pixelCount)
. It’s exported, so we can see it in the watcher or set values over websockets.
We also set some values by index.
export function render(index) {
hsv(number[index] ? 0.0 : 0.66 , sat , number[index] ? 1 : bri )
Compute each pixel. If the corresponding entry in the matrix is zero, the hue will red (0) and the brightness will be full-on (1). Otherwise, if the array has a nonzero entry in this pixel index, the hue will be full blue (.66) and the brightness will be set to bri
, which is presumably set elsewhere, perhaps in the global code or with a UI slider.
OK - that seems like a data-series (array) driven input to render. Where else are you stuck?
Jumping to the Scrolling Text Marquee pattern, here’s the point where the message-of-characters array (message
) is used.
Context: This is called when a timer tells us it’s time to shift the message over by one column. That might involve loading the next character, or reloading the same char we’re only partway through.
function loadNextCol() {
charIndex = message[floor(messageColPointer / charCols)]
fetchCharacter(charIndex) // loads global `character` with ASCII charIndex
charIndex
: The index (0-based address in the array) of the character (like “A”)'s ascii value (like 65
). So, if the message was “HA!” then the array would be ["H", "A", "!"]
and charIndex
of “A” would be 1
.
messageColPointer
: The index of an array that stores all bits for columns for the message. Since the font has 8 columns in a character (charCols
== 8), messageColPointer for “HA!” goes from 0 to 23. A messageColPointer of 8 would be the leftmost column of pixels for the A in “HA!”
Keep up the good work learning arrays in PB. They unlock a lot of goodness.