60 lines
1.3 KiB
C++
60 lines
1.3 KiB
C++
//
|
|
// ScreensaverPlugin.cpp
|
|
// tmp
|
|
//
|
|
// Created by Bob Polis at 2020-10-26
|
|
// Copyright (c) 2020 SwiftCoder. All rights reserved.
|
|
//
|
|
|
|
#include "ScreensaverPlugin.hpp"
|
|
|
|
void ScreensaverPlugin::setup(cairo_t* context, const cairo_rectangle_t& rect) {
|
|
_c = context;
|
|
_r = rect;
|
|
}
|
|
|
|
void ScreensaverPlugin::make_black() {
|
|
cairo_set_source_rgb(_c, 0, 0, 0);
|
|
cairo_rectangle(_c, 0, 0, _r.width, _r.height);
|
|
cairo_fill(_c);
|
|
}
|
|
|
|
cairo_rectangle_t ScreensaverPlugin::random_rect() {
|
|
cairo_rectangle_t rect;
|
|
double v1, v2;
|
|
v1 = random_x();
|
|
v2 = random_x();
|
|
if (v1 < v2) {
|
|
rect.x = v1;
|
|
rect.width = v2 - v1;
|
|
} else {
|
|
rect.x = v2;
|
|
rect.width = v1 - v2;
|
|
}
|
|
v1 = random_y();
|
|
v2 = random_y();
|
|
if (v1 < v2) {
|
|
rect.y = v1;
|
|
rect.height = v2 - v1;
|
|
} else {
|
|
rect.y = v2;
|
|
rect.height = v1 - v2;
|
|
}
|
|
return rect;
|
|
}
|
|
|
|
double ScreensaverPlugin::random_x() {
|
|
std::uniform_real_distribution<double> dist {0, _r.width};
|
|
return dist(_eng);
|
|
}
|
|
|
|
double ScreensaverPlugin::random_y() {
|
|
std::uniform_real_distribution<double> dist {0, _r.height};
|
|
return dist(_eng);
|
|
}
|
|
|
|
double ScreensaverPlugin::random01() {
|
|
std::uniform_real_distribution<double> dist {};
|
|
return dist(_eng);
|
|
}
|