diff options
| author | dario-loi <77234595+dario-loi@users.noreply.github.com> | 2024-11-24 14:46:27 +0100 |
|---|---|---|
| committer | dario-loi <loi.1940849@studenti.uniroma1.it> | 2024-11-24 18:38:21 +0100 |
| commit | 8183b19a87f7b6be35bceef11ace399d876d158b (patch) | |
| tree | a56c6368ff4f8dda180abca577c70b54079afc6c /example/rectangle.c | |
| parent | 76a7cf28f44820d1db2e02980201657186190d43 (diff) | |
| parent | 0898b3d26129f3880223d0d457fe05fd3f6be180 (diff) | |
Merge branch 'lvntky:master' into master
Diffstat (limited to 'example/rectangle.c')
| -rw-r--r-- | example/rectangle.c | 102 |
1 files changed, 52 insertions, 50 deletions
diff --git a/example/rectangle.c b/example/rectangle.c index 73f9c4b..ecc1afd 100644 --- a/example/rectangle.c +++ b/example/rectangle.c @@ -3,57 +3,59 @@ int main(int argc, char *argv[]) { - fbgl_t buffer; - if (fbgl_init("/dev/fb0", &buffer) == -1) { - fprintf(stdout, "Error: could not open framebuffer device\n"); - return -1; - } - - fbgl_set_bg(&buffer, 0xFFFFFF); // Set the background to white - - fbgl_point_t start = {100, 100}; - fbgl_point_t end = {200, 200}; - fbgl_draw_rectangle_outline(start, end, 0xFF0000, &buffer); // Draw red rectangle outline - - fbgl_point_t start2 = {600, 400}; - fbgl_point_t end2 = {800, 800}; - uint32_t colors[] = {0xFFC00, 0x00FF00, 0x0000FF, 0xFF00FF}; // Yellow, Green, Blue, Magenta - size_t color_index = 0; - - // Initial position of the marquee rectangle - int dx = 15; // Horizontal speed - int dy = 8; // Vertical speed - - while (1) { - // Clear the framebuffer (set background) - fbgl_set_bg(&buffer, 0xFFFFFF); - - - // Draw the moving filled rectangle - fbgl_draw_rectangle_filled(start2, end2, colors[color_index], &buffer); - - // Move the filled rectangle by updating its position - start2.x += dx; - end2.x += dx; - start2.y += dy; - end2.y += dy; - - // Reverse direction if the rectangle hits the screen boundary - if (start2.x <= 0 || end2.x >= buffer.width) { - dx = -dx; - color_index++; - } - if (start2.y <= 0 || end2.y >= buffer.height) { - dy = -dy; - color_index++; - } - if (color_index >= 4) { - color_index = 0; + fbgl_t buffer; + if (fbgl_init("/dev/fb0", &buffer) == -1) { + fprintf(stdout, "Error: could not open framebuffer device\n"); + return -1; } - usleep(50000); // Delay to make the animation visible (adjust as needed) - } + fbgl_set_bg(&buffer, 0xFFFFFF); // Set the background to white + + fbgl_point_t start = { 100, 100 }; + fbgl_point_t end = { 200, 200 }; + fbgl_draw_rectangle_outline(start, end, 0xFF0000, + &buffer); // Draw red rectangle outline + + fbgl_point_t start2 = { 600, 400 }; + fbgl_point_t end2 = { 800, 800 }; + uint32_t colors[] = { 0xFFC00, 0x00FF00, 0x0000FF, + 0xFF00FF }; // Yellow, Green, Blue, Magenta + size_t color_index = 0; + + // Initial position of the marquee rectangle + int dx = 15; // Horizontal speed + int dy = 8; // Vertical speed + + while (1) { + // Clear the framebuffer (set background) + fbgl_set_bg(&buffer, 0xFFFFFF); + + // Draw the moving filled rectangle + fbgl_draw_rectangle_filled(start2, end2, colors[color_index], + &buffer); + + // Move the filled rectangle by updating its position + start2.x += dx; + end2.x += dx; + start2.y += dy; + end2.y += dy; + + // Reverse direction if the rectangle hits the screen boundary + if (start2.x <= 0 || end2.x >= buffer.width) { + dx = -dx; + color_index++; + } + if (start2.y <= 0 || end2.y >= buffer.height) { + dy = -dy; + color_index++; + } + if (color_index >= 4) { + color_index = 0; + } + + usleep(50000); // Delay to make the animation visible (adjust as needed) + } - fbgl_destroy(&buffer); - return 0; + fbgl_destroy(&buffer); + return 0; } |
