Skip to content

Instantly share code, notes, and snippets.

@zeffii
Forked from anonymous/duplo.sq
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zeffii/9387777 to your computer and use it in GitHub Desktop.
Save zeffii/9387777 to your computer and use it in GitHub Desktop.
function writeRGBString(tpixel, color)
{
local r = color[0] * BYTESPERCOLOR;
local g = color[1] * BYTESPERCOLOR;
local b = color[2] * BYTESPERCOLOR;
tpixel.writestring(bits.slice(g, g+BYTESPERCOLOR));
tpixel.writestring(bits.slice(r, r+BYTESPERCOLOR));
tpixel.writestring(bits.slice(b, b+BYTESPERCOLOR));
}
function writePixel(p, color)
{
frame.seek(p*BYTESPERPIXEL);
writeRGBString(frame, color);
}
// Clears the frame buffer (with an optional color)
// but does not write it to the pixel strip
// color is an array of the form [r, g, b]
function clearFrame(color = null)
{
local colorString = clearString;
if (color)
{
// Get the color string
colorString = blob(BYTESPERPIXEL);
writeRGBString(colorString, color);
}
frame.seek(0);
for (local p = 0; p < frameSize; p++) frame.writestring(colorString.tostring());
frame.writen(0x00,'c');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment