starts with random hue; adapted to new random number functions; rectangles can extend beyond window

This commit is contained in:
Bob Polis 2020-11-16 10:45:31 +01:00
parent 291678d06a
commit 124acffc01

View File

@ -13,7 +13,6 @@
#include <iomanip>
#include <vector>
#include <algorithm>
#include <random>
const int default_frames_per_rect {10};
@ -45,6 +44,7 @@ class FadingRects : public ScreensaverPlugin {
FadingRects() = default;
~FadingRects() = default;
void setup(cairo_t* context, const cairo_rectangle_t& rect) override;
int fps() const override;
void update () override;
void render() override;
@ -53,7 +53,6 @@ class FadingRects : public ScreensaverPlugin {
double _hue {0.0};
std::vector<Rect> _rects;
int _frames_per_rect {default_frames_per_rect};
std::uniform_real_distribution<double> _random_line_width {1.0, 20.0};
Color next_color();
};
@ -63,7 +62,7 @@ ScreensaverPlugin* create_instance() {
}
int FadingRects::fps() const {
return 30;
return 20;
}
void FadingRects::update() {
@ -97,7 +96,12 @@ void FadingRects::update() {
_frames_per_rect--;
if (_frames_per_rect == 0) {
_frames_per_rect = default_frames_per_rect;
cairo_rectangle_t rr {random_rect()};
cairo_rectangle_t rr {_r};
rr.x -= 50.0;
rr.y -= 50.0;
rr.width += 100.0;
rr.height += 100.0;
rr = random_rect_in_rect(rr);
RGB rgb {RGB(next_color())};
Rect rect;
rect.red = rgb.r;
@ -108,7 +112,7 @@ void FadingRects::update() {
rect.state = FadingState::fadein;
rect.sustain_frame = 0;
rect.delta = rect.alpha / (5 * fps());
rect.line_width = _random_line_width(_eng);
rect.line_width = random_between(1.0, 20.0);
rect.x = rr.x;
rect.y = rr.y;
rect.width = rr.width;
@ -141,3 +145,9 @@ Color FadingRects::next_color() {
hsb.b = random01();
return Color {hsb};
}
void FadingRects::setup(cairo_t* context, const cairo_rectangle_t& rect) {
ScreensaverPlugin::setup(context, rect);
std::uniform_real_distribution<double> dist {0.0, 360.0};
_hue = dist(_eng);
}