made the animation more fancy
This commit is contained in:
parent
472be95b86
commit
0a41b25368
22
main.cpp
22
main.cpp
@ -44,6 +44,10 @@ void timer_signal_handler(int /*sig*/, siginfo_t* /*si*/, void* /*uc*/) {
|
||||
void draw() {
|
||||
static int x = 300;
|
||||
static int y = 300;
|
||||
static int dx = 1;
|
||||
static int dy = 1;
|
||||
static double r = 0;
|
||||
static double dr = 0.01;
|
||||
|
||||
if (timer_expired) {
|
||||
timer_expired = false;
|
||||
@ -61,7 +65,7 @@ void draw() {
|
||||
|
||||
// black rectangle
|
||||
cairo_rectangle(cr, 200, 200, 100, 100);
|
||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||
cairo_set_source_rgb(cr, r, 0, 0);
|
||||
cairo_fill(cr);
|
||||
|
||||
// dark green text
|
||||
@ -75,10 +79,14 @@ void draw() {
|
||||
main_window->show_image(*main_image);
|
||||
|
||||
// update
|
||||
x++;
|
||||
y++;
|
||||
if (x > 400) x = 300;
|
||||
if (y > 400) y = 300;
|
||||
x += dx;
|
||||
y += dy;
|
||||
if (x > 400) dx = -1;
|
||||
if (y > 400) dy = -1;
|
||||
if (x < 300) dx = 1;
|
||||
if (y < 300) dy = 1;
|
||||
r += dr;
|
||||
if (r > 1) r = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@ -135,7 +143,7 @@ int main(int argc, const char * argv[]) {
|
||||
sev.sigev_value.sival_ptr = &timer;
|
||||
struct itimerspec ts;
|
||||
ts.it_interval.tv_sec = 0;
|
||||
ts.it_interval.tv_nsec = 100000000;
|
||||
ts.it_interval.tv_nsec = 25000000;
|
||||
ts.it_value.tv_sec = 0;
|
||||
ts.it_value.tv_nsec = 1;
|
||||
throw_if_min1(timer_create(CLOCK_REALTIME, &sev, &timer));
|
||||
@ -146,7 +154,7 @@ int main(int argc, const char * argv[]) {
|
||||
sc::gui::SDLImageWrapper sdl_image;
|
||||
|
||||
// main window
|
||||
sc::gui::Window& window {sc::gui::Window::new_window("screensaver")};
|
||||
sc::gui::Window& window {sc::gui::Window::new_window("living art")};
|
||||
main_window = &window;
|
||||
window.add_event_handler([](const SDL_Event& event, bool quit) -> bool {
|
||||
std::cerr << "closing window " << event.window.windowID << '\n';
|
||||
|
Loading…
x
Reference in New Issue
Block a user