diff --git a/examples/button.c b/examples/button.c index be4a0a0..a163ec7 100644 --- a/examples/button.c +++ b/examples/button.c @@ -1,30 +1,23 @@ #include #include +#include #include -#include - -static const float color_step = 10.0f; +static const float step = 5.0f; +static float hue = 360.0f; static PtkRect *r; static void on_press(const int button, const int mods) { (void)button; (void)mods; PTK_DEBUG("pressed!"); - r->color.b += color_step / 255.0f; - if (r->color.b > 1.0f) { - r->color.b = 0.0f; - r->color.g += color_step / 255.0f; - if (r->color.g > 1.0f) { - r->color.g = 0.0f; - - r->color.r += color_step / 255.0f; - if (r->color.r > 1.0f) { - r->color.r = 0.0f; - } - } + hue += step; + if (hue > 360.0f) { + hue = 0.0f; } + + r->color = ptk_hsv_to_rgb((PtkHSV){ .h = hue, .s = 360.0f, .v = 360.0f }); } int main(void) { @@ -35,7 +28,7 @@ int main(void) { r = (PtkRect *)ptk_rect( (PtkPos){ .x = 100.0f, .y = 100.0f }, (PtkSize){ .w = 100.0f, .h = 50.0f }, - (PtkRGB){ .r = 1.0f, .g = 1.0f, .b = 1.0f } + (PtkRGB){ .r = 1.0f, .g = 0.0f, .b = 0.0f } ); return ptk_run(