Change fixed colors to animated colors

This commit is contained in:
2025-10-29 11:13:45 +01:00
parent c862e584e0
commit 3e37d54b5c
2 changed files with 18 additions and 6 deletions

View File

@@ -30,6 +30,7 @@ private:
Color _stroke_color {"#FFFFFF"}; Color _stroke_color {"#FFFFFF"};
Color _fill_color {"#606060"}; Color _fill_color {"#606060"};
std::vector<Point> _points; std::vector<Point> _points;
double _hue;
}; };
ScreensaverPlugin *create_instance() { return new Polygon; } ScreensaverPlugin *create_instance() { return new Polygon; }
@@ -39,8 +40,6 @@ void Polygon::configure() {
_min_speed = _j["min-speed"]; _min_speed = _j["min-speed"];
_max_speed = _j["max-speed"]; _max_speed = _j["max-speed"];
_stroke_width = _j["stroke-width"]; _stroke_width = _j["stroke-width"];
_stroke_color = _j["stroke-color"];
_fill_color = _j["fill-color"];
for (int i = 0; i < _num_points; ++i) { for (int i = 0; i < _num_points; ++i) {
Point p; Point p;
p.x = random_x(); p.x = random_x();
@@ -51,6 +50,7 @@ void Polygon::configure() {
p.speed_y *= random_bool() ? 1 : -1; p.speed_y *= random_bool() ? 1 : -1;
_points.push_back(p); _points.push_back(p);
} }
_hue = random_between(0.0, 360.0);
} }
void Polygon::size_changed() { void Polygon::size_changed() {
@@ -63,6 +63,7 @@ void Polygon::size_changed() {
std::string Polygon::version() const { return "1.0.0"; } std::string Polygon::version() const { return "1.0.0"; }
void Polygon::update() { void Polygon::update() {
// update points
for (Point& p : _points) { for (Point& p : _points) {
p.x += p.speed_x; p.x += p.speed_x;
if (p.x < 0 || p.x > _r.width) { if (p.x < 0 || p.x > _r.width) {
@@ -75,6 +76,19 @@ void Polygon::update() {
p.y += p.speed_y; p.y += p.speed_y;
} }
} }
// update hue
_hue += 0.5;
if (_hue >= 360.0) {
_hue -= 360.0;
}
// construct stroke and fill colors
HSB hsb;
hsb.h = _hue;
hsb.s = 1.0;
hsb.b = 0.1;
_fill_color = hsb;
hsb.b = 0.7;
_stroke_color = hsb;
} }
void Polygon::render() { void Polygon::render() {

View File

@@ -1,8 +1,6 @@
{ {
"num-points": 7, "num-points": 42,
"min-speed": 0.2, "min-speed": 0.2,
"max-speed": 2.0, "max-speed": 2.0,
"stroke-width": 3.0, "stroke-width": 3.0
"stroke-color": "#00D000",
"fill-color": "#006000"
} }