So here's a challenge - setting up "viewport" clipping on a 32x32 matrix.

So here’s a challenge - setting up “viewport” clipping on a 32x32 matrix. example: I want to have a status line, 6 x 32. Instead of drawing a black rectangle, which will interfere with blurs and other effects, have a method of limiting effects to exclude that area, unless explicitly drawn into it, like a text scroller.

Any ideas? I tried just limiting the blur2d command to this: blur2d(leds, kMatrixWidth, kMatrixHeight - 6, blurAmount)l but that gives a really odd effect, instead of leaving the area empty. I can draw a black rectangle over top, but that seems to mess up the blur anyways.

The foreground routines in the Smartmatrix lib don’t seem to have a way to draw a black rectangle. Unless I’m missing something entirely, I can only seem to set white pixels.

I also tried the following, to see if I could make a faded overlay, and it doesn’t seem to do anything at all:

fract8 fraction = 0.5;
for(int q=0; q<32; q++) {
for(int w=26;w<32;w++) {
CRGB newPixel = blend(CRGB(leds[XY(q,w)]), CRGB(32,32,32), fraction);
pSmartMatrix->drawPixel(q,w,newPixel);
}
}

Manually set newPixel to CRGB(32,32,32), I get a gray box that gets blurred by the other routines.

You’re right, the pixels in the foreground layer are either opaque or transparent, and all the opaque pixels are the same color. You can’t set a foreground pixel to both black and white for example.

I can see how what you want to do would be useful, but don’t have a good suggestion of how to implement it right now.

Well, I can sort of see a very memory-wasteful method of doing “foreground” drawing - two complete copies of the LED array. Do the background, save to storage array, do foreground & display it, then recopy the storage to the LEDs after the display. memcpy should do the trick, so speed isn’t a problem.I’ll play with it.

Edit: And it works like a charm, actually. More memory used, but now I have full-color foreground items.

Basically, do this:

CRGB leds[NUM_LEDS];
CRGB storage[NUM_LEDS];

// do background stuff here
memcpy(storage, leds, sizeof(leds));
// do foreground stuff here
FastLED.show();
// restore background
memcpy(leds,storage, sizeof(leds));

It’s not viewport clipping, but I can fake it with this.

Try using 128 instead of 0.5.

“fract8” is an eight bit integer value representing a number of 256ths. So “128” is how you say “half” in fract8. More of that fixed-point math.

Aha. I looked around, couldn’t find anything on it, just “uses fract8”. Thanks.

Now the final hurdle, and it’s a purely physical one, is that of visual clarity - it’s a shame, but tiny fonts are nigh-unreadable on the matrix. I may have to make a tiny font just for the numbers, since the main purpose of this was to have a small clock version in the corner.

Try this font, the numbers are simple: http://robey.lag.net/2010/01/23/tiny-monospace-font.html

It’s available in BDF and I updated bdf2c to make it easier to create fonts for SmartMatrix (use the -s option):

You could probably shrink your viewport array down to just the size of your black box, but that would complicate memcpy operations. It would be interesting to introduce partial transparency by using a blend function instead of memcpy to add the black box, but that might not be the look you want.