Compare commits

...

7 Commits

Author SHA1 Message Date
ffda761acc Use transparency for the fill color 2025-10-29 11:21:34 +01:00
43363b53b7 Bump version 1.0.0 → 1.1.0 2025-10-29 11:14:32 +01:00
3e37d54b5c Change fixed colors to animated colors 2025-10-29 11:13:45 +01:00
c862e584e0 Remove unnecessary empty line 2025-10-27 12:21:13 +01:00
680fd485c7 Bump version 1.2.0 → 1.2.1 2025-10-27 11:41:05 +01:00
fe3aa3b76c Use configure() instead of setup() for init 2025-10-27 11:39:40 +01:00
f7080fb83d Remove direct libscnumerics dependency
And use random_between() function
2025-10-27 11:36:20 +01:00
5 changed files with 25 additions and 20 deletions

View File

@@ -2,7 +2,6 @@
#include <cairo/cairo.h> #include <cairo/cairo.h>
#include <libscscreensaver.hpp> #include <libscscreensaver.hpp>
#include <libsccolor.hpp> #include <libsccolor.hpp>
#include <libscnumerics.hpp>
#include <vector> #include <vector>
#include <algorithm> #include <algorithm>
@@ -36,7 +35,7 @@ class FadingRects : public ScreensaverPlugin {
FadingRects() = default; FadingRects() = default;
~FadingRects() = default; ~FadingRects() = default;
void setup(cairo_t* context, const cairo_rectangle_t& rect) override; void configure() override;
int fps() const override; int fps() const override;
void update () override; void update () override;
void render() override; void render() override;
@@ -55,7 +54,7 @@ ScreensaverPlugin* create_instance() {
} }
std::string FadingRects::version() const { std::string FadingRects::version() const {
return "1.2.0"; return "1.2.1";
} }
int FadingRects::fps() const { int FadingRects::fps() const {
@@ -151,8 +150,7 @@ Color FadingRects::next_color() {
return Color {hsb}; return Color {hsb};
} }
void FadingRects::setup(cairo_t* context, const cairo_rectangle_t& rect) { void FadingRects::configure() {
ScreensaverPlugin::setup(context, rect); _hue = random_between(0.0, 360.0);
_hue = sc::random::double_between(0.0, 360.0);
_rects.clear(); _rects.clear();
} }

View File

@@ -1,4 +1,4 @@
LDLIBS := -lcairo -lscscreensaver -lscnumerics -lsccolor LDLIBS := -lcairo -lscscreensaver -lsccolor
UNAME_S := $(shell uname -s) UNAME_S := $(shell uname -s)
PROJ := $(shell basename $$(pwd)) PROJ := $(shell basename $$(pwd))
PLUGIN := $(PROJ).saver PLUGIN := $(PROJ).saver

View File

@@ -27,9 +27,9 @@ private:
double _min_speed {0.2}; double _min_speed {0.2};
double _max_speed {2.0}; double _max_speed {2.0};
double _stroke_width {1.0}; double _stroke_width {1.0};
Color _stroke_color {"#FFFFFF"}; Color _color {"#FFFFFF"};
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 +39,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 +49,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() {
@@ -60,9 +59,10 @@ void Polygon::size_changed() {
} }
} }
std::string Polygon::version() const { return "1.0.0"; } std::string Polygon::version() const { return "1.1.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 +75,17 @@ 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 color
HSB hsb;
hsb.h = _hue;
hsb.s = 1.0;
hsb.b = 0.7;
_color = hsb;
} }
void Polygon::render() { void Polygon::render() {
@@ -87,11 +98,10 @@ void Polygon::render() {
cairo_line_to(_c, p.x, p.y); cairo_line_to(_c, p.x, p.y);
} }
cairo_close_path(_c); cairo_close_path(_c);
RGB c = RGB(_stroke_color); RGB c = RGB(_color);
cairo_set_source_rgb(_c, c.r, c.g, c.b); cairo_set_source_rgb(_c, c.r, c.g, c.b);
cairo_set_line_width(_c, _stroke_width); cairo_set_line_width(_c, _stroke_width);
cairo_stroke_preserve(_c); cairo_stroke_preserve(_c);
RGB f = RGB(_fill_color); cairo_set_source_rgba(_c, c.r, c.g, c.b, 0.2);
cairo_set_source_rgb(_c, f.r, f.g, f.b);
cairo_fill(_c); cairo_fill(_c);
} }

View File

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

View File

@@ -42,7 +42,6 @@ void print_help() {
void list_plugins() { void list_plugins() {
for (const auto& elem : sc::plugin<ScreensaverPlugin>::all()) { for (const auto& elem : sc::plugin<ScreensaverPlugin>::all()) {
std::cout << elem.first << " (" << elem.second()->version() << ")\n"; std::cout << elem.first << " (" << elem.second()->version() << ")\n";
} }
} }