screensaver/skembo/Skembo.cpp

54 lines
974 B
C++
Raw Normal View History

2020-10-27 23:57:25 +01:00
//
// 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;
2020-10-28 17:58:47 +01:00
void draw_frame() override;
2020-10-27 23:57:25 +01:00
private:
double _hue {0};
};
ScreensaverPlugin* create_instance() {
return new Skembo;
}
int Skembo::fps() const {
2020-10-28 16:29:35 +01:00
return 40;
2020-10-27 23:57:25 +01:00
}
void Skembo::draw_frame() {
2020-10-28 16:29:35 +01:00
// next color
2020-10-27 23:57:25 +01:00
HSB hsb;
hsb.h = _hue;
2020-10-28 16:29:35 +01:00
hsb.s = 1.0;
hsb.b = 0.4;
// convert to rgb
2020-10-27 23:57:25 +01:00
Color color {hsb};
RGB rgb {RGB(color)};
2020-10-28 16:29:35 +01:00
// setup color, fill whole window
2020-10-27 23:57:25 +01:00
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);
2020-10-28 16:29:35 +01:00
// update for next frame
_hue += 0.5;
2020-10-27 23:57:25 +01:00
if (_hue > 360.0) {
2020-10-28 16:29:35 +01:00
_hue -= 360.0;
2020-10-27 23:57:25 +01:00
}
}