screensaver/skembo/Skembo.cpp
2020-10-28 17:58:47 +01:00

54 lines
974 B
C++

//
// Skembo.cpp
// screensaver
//
// Created by Bob Polis at 2020-10-26
// Copyright (c) 2020 SwiftCoder. All rights reserved.
//
#include "Skembo.hpp"
#include <libscscreensaver.hpp>
class Skembo : public ScreensaverPlugin {
public:
Skembo() = default;
~Skembo() = default;
int fps() const override;
void draw_frame() override;
private:
double _hue {0};
};
ScreensaverPlugin* create_instance() {
return new Skembo;
}
int Skembo::fps() const {
return 40;
}
void Skembo::draw_frame() {
// next color
HSB hsb;
hsb.h = _hue;
hsb.s = 1.0;
hsb.b = 0.4;
// convert to rgb
Color color {hsb};
RGB rgb {RGB(color)};
// setup color, fill whole window
cairo_set_source_rgb(_c, rgb.r, rgb.g, rgb.b);
cairo_rectangle(_c, _r.x, _r.y, _r.width, _r.height);
cairo_fill(_c);
// update for next frame
_hue += 0.5;
if (_hue > 360.0) {
_hue -= 360.0;
}
}