Mercurial > public > algo-animator
comparison main.c @ 5:6be2faa7ed6e
rectangles with variable height
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Tue, 13 Jun 2023 17:23:52 +0100 |
parents | 035d3880da04 |
children | 40a8bdbe2005 |
comparison
equal
deleted
inserted
replaced
4:035d3880da04 | 5:6be2faa7ed6e |
---|---|
1 #include "utils.h" | 1 #include "utils.h" |
2 #include <stdio.h> | |
3 #include <stdlib.h> | |
4 #include <math.h> | |
5 #include <time.h> | |
2 | 6 |
3 | 7 |
4 #define HEIGHT 1080 | 8 #define HEIGHT 1080 |
5 #define WIDTH 1920 | 9 #define WIDTH 1920 |
6 | 10 |
28 glBegin(GL_QUADS); | 32 glBegin(GL_QUADS); |
29 | 33 |
30 float x = 1; | 34 float x = 1; |
31 float rect_width = 5.0; | 35 float rect_width = 5.0; |
32 float space = 5.0; | 36 float space = 5.0; |
37 | |
38 // Compute max number of rectangles to fit the windows | |
33 int max_rects = floor((WIDTH - rect_width) / (rect_width + space)) + x; | 39 int max_rects = floor((WIDTH - rect_width) / (rect_width + space)) + x; |
34 | 40 |
41 // Initialize empty array with same of `max_rects` | |
42 int *unsorted_array = (int*)malloc(max_rects * sizeof(int)); | |
43 | |
35 int rect_counter = 0; | 44 int rect_counter = 0; |
36 while (rect_counter < max_rects) { | 45 while (rect_counter < max_rects) { |
37 glVertex2f(x, 100.0); | 46 int height = random_int(100, HEIGHT - 100); |
38 glVertex2f(x + rect_width, 100.0); | 47 |
39 glVertex2f(x + rect_width, HEIGHT - 300); | 48 glVertex2f(x, HEIGHT - 100); |
40 glVertex2d(x, HEIGHT - 300); | 49 glVertex2f(x + rect_width, HEIGHT - 100); |
50 glVertex2f(x + rect_width, height); | |
51 glVertex2d(x, height); | |
41 | 52 |
42 x += rect_width + space; | 53 x += rect_width + space; |
43 rect_counter++; | 54 rect_counter++; |
44 } | 55 } |
45 | 56 |
46 glEnd(); | 57 glEnd(); |
47 | 58 |
48 char text[256]; | 59 char text[256]; |
49 sprintf(text, "Number of elements: %i", rect_counter); | 60 sprintf(text, "Number of elements: %i", rect_counter); |
50 render_text(text, 20.0, HEIGHT - 200); | 61 render_text(text, 20.0, HEIGHT - 50); |
51 glFlush(); | 62 glFlush(); |
52 } | 63 } |
53 | 64 |
54 | 65 |
55 int main(int argc, char** argv) { | 66 int main(int argc, char** argv) { |