Open jpasqua opened 8 years ago
I wouldn't mind trying out your demo, but you did not provide the source for the HSV to RGB utilities you are using...
Sorry about that. I added the following to graphics.h right below the definition of the Color struct:
struct HSVColor {
HSVColor(uint8_t h_, uint8_t s_, uint8_t v_) : h(h_), s(s_), v(v_) {}
uint8_t h;
uint8_t s;
uint8_t v;
};
Color HsvToRGB(HSVColor hsv);
and the following function to graphics.cc
Color HsvToRGB(HSVColor hsv)
{
Color rgb(hsv.v, hsv.v, hsv.v); // Default to case where hsv.s == 0
unsigned char region, remainder, p, q, t;
if (hsv.s == 0) return rgb;
region = hsv.h / 43;
remainder = (hsv.h - (region * 43)) * 6;
p = (hsv.v * (255 - hsv.s)) >> 8;
q = (hsv.v * (255 - ((hsv.s * remainder) >> 8))) >> 8;
t = (hsv.v * (255 - ((hsv.s * (255 - remainder)) >> 8))) >> 8;
switch (region)
{
case 0:
rgb.r = hsv.v; rgb.g = t; rgb.b = p;
break;
case 1:
rgb.r = q; rgb.g = hsv.v; rgb.b = p;
break;
case 2:
rgb.r = p; rgb.g = hsv.v; rgb.b = t;
break;
case 3:
rgb.r = p; rgb.g = q; rgb.b = hsv.v;
break;
case 4:
rgb.r = t; rgb.g = p; rgb.b = hsv.v;
break;
default:
rgb.r = hsv.v; rgb.g = p; rgb.b = q;
break;
}
return rgb;
}
Great example! I adapted it for the new DemoRunner class and double buffering code in the code as of Jan '22 (probably earlier) - if anybody's interested in getting this code, pm me. Top tip - set the usleep to 30ms instead of 100, as that was way too stuttery, however I'm running this on a new fangled Pi Zero 2 W on a 64x64 matrix, so ymmv. Getting a slightly jarring interrupt in the animation where the plasma changes shape abruptly - any ideas why?
I'm not in a great position to submit a pull request at the moment (I've made a lot of poorly managed changes during experimentation), but I thought I'd pass this along in case someone wants to integrate it properly. It is a new Plasma demo which looks a bit like a lava lamp.
Add the new Plasma class anywhere convenient in demo-main.cc:
Add the following case to the main switch statement which selects which demo to run:
I don't see a big difference with and without double buffering on an RPi2. This could be removed without sacrificing much.