Hi all! I’m new to PixelBlaze and don’t have a lot of experience with JavaScript. I’m wondering how you can use a hex code like you’d find in HTML (e.g. #FF0A52) either in a color picker or by pasting it into the pattern directly. It seems numbers can’t go beyond 16.16 fixed point format, and strings are disabled. I’d like to start with a simple static color for my LEDs: just paste in a hex code you find, and boom, the lights update. Ultimately, I’d love to code gradients or more complex patterns, but I need to start with hex codes to match color styles that I’m using.
I couldn’t find how to do this in the examples or forum, so any help would be appreciated!
The main issue is that Pixelbaze doesn’t support strings! But also what you mentioned, which is that we need 24 bits for HTML colors, but we typically use the fractional 16 bits to express and output out values for r, g, & b or h, s, & v.
I haven’t seen any patterns do this before, and apologies because I don’t have a Pixelblaze with me to test, but I suspect something like this should work:
// HTML Color #FF0A52
export var color = [0xFF, 0x0A, 0x52]
export function render(index) {
rgb(color[0]/255, color[1]/255, color[2]/255)
}
Optimizing compiler? What fun would that leave us?!?
Use the mutate method to change an array in place. The map method in JavaScript would create a new array, and we don’t want that (and it doesn’t exist in PB’s subset.)
We also have a mapTo when you do need a copy instead of a change in place, that works on 2 arrays.