Change fixed colors to animated colors
This commit is contained in:
@@ -30,6 +30,7 @@ private:
|
||||
Color _stroke_color {"#FFFFFF"};
|
||||
Color _fill_color {"#606060"};
|
||||
std::vector<Point> _points;
|
||||
double _hue;
|
||||
};
|
||||
|
||||
ScreensaverPlugin *create_instance() { return new Polygon; }
|
||||
@@ -39,8 +40,6 @@ void Polygon::configure() {
|
||||
_min_speed = _j["min-speed"];
|
||||
_max_speed = _j["max-speed"];
|
||||
_stroke_width = _j["stroke-width"];
|
||||
_stroke_color = _j["stroke-color"];
|
||||
_fill_color = _j["fill-color"];
|
||||
for (int i = 0; i < _num_points; ++i) {
|
||||
Point p;
|
||||
p.x = random_x();
|
||||
@@ -51,6 +50,7 @@ void Polygon::configure() {
|
||||
p.speed_y *= random_bool() ? 1 : -1;
|
||||
_points.push_back(p);
|
||||
}
|
||||
_hue = random_between(0.0, 360.0);
|
||||
}
|
||||
|
||||
void Polygon::size_changed() {
|
||||
@@ -63,6 +63,7 @@ void Polygon::size_changed() {
|
||||
std::string Polygon::version() const { return "1.0.0"; }
|
||||
|
||||
void Polygon::update() {
|
||||
// update points
|
||||
for (Point& p : _points) {
|
||||
p.x += p.speed_x;
|
||||
if (p.x < 0 || p.x > _r.width) {
|
||||
@@ -75,6 +76,19 @@ void Polygon::update() {
|
||||
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() {
|
||||
|
||||
Reference in New Issue
Block a user