comparison main.c @ 16:2ded5f1f544a

refactor variable name
author Dennis C. M. <dennis@denniscm.com>
date Sun, 25 Jun 2023 16:52:44 +0100
parents e2fcfcb43fee
children fba66d02f1cf
comparison
equal deleted inserted replaced
15:e2fcfcb43fee 16:2ded5f1f544a
8 #include FT_FREETYPE_H 8 #include FT_FREETYPE_H
9 9
10 10
11 #define WINDOW_HEIGHT 1080 11 #define WINDOW_HEIGHT 1080
12 #define WINDOW_WIDTH 1920 12 #define WINDOW_WIDTH 1920
13 #define OFFSET 150 13 #define VPADDING 150
14 #define RECT_WIDTH 5 14 #define RECT_WIDTH 5
15 #define SPACE 1 15 #define SPACE 1
16 16
17 17
18 /* Global variables */ 18 /* Global variables */
71 arr_size = floor((WINDOW_WIDTH - RECT_WIDTH) / (RECT_WIDTH + SPACE)) + 1; 71 arr_size = floor((WINDOW_WIDTH - RECT_WIDTH) / (RECT_WIDTH + SPACE)) + 1;
72 arr = (int*)malloc(arr_size * sizeof(int)); 72 arr = (int*)malloc(arr_size * sizeof(int));
73 73
74 srand(time(NULL)); 74 srand(time(NULL));
75 75
76 int min = OFFSET; 76 int min = VPADDING;
77 int max = WINDOW_HEIGHT - OFFSET; 77 int max = WINDOW_HEIGHT - VPADDING;
78 78
79 for (int i = 0; i < arr_size; i++) { 79 for (int i = 0; i < arr_size; i++) {
80 arr[i] = rand() % ((max - min) + 1) + min; 80 arr[i] = rand() % ((max - min) + 1) + min;
81 } 81 }
82 } 82 }
156 156
157 glyph_bitmap->buffer = flipped_bitmap; 157 glyph_bitmap->buffer = flipped_bitmap;
158 158
159 // Calculate the adjusted y position based on the glyph's bearing 159 // Calculate the adjusted y position based on the glyph's bearing
160 int adjusted_y = y + (slot->bitmap_top - glyph_bitmap->rows); 160 int adjusted_y = y + (slot->bitmap_top - glyph_bitmap->rows);
161 161
162 glRasterPos2f(x, adjusted_y); 162 glRasterPos2f(x, adjusted_y);
163 glDrawPixels(glyph_bitmap->width, glyph_bitmap->rows, GL_LUMINANCE, GL_UNSIGNED_BYTE, glyph_bitmap->buffer); 163 glDrawPixels(glyph_bitmap->width, glyph_bitmap->rows, GL_LUMINANCE, GL_UNSIGNED_BYTE, glyph_bitmap->buffer);
164 164
165 x += 15; 165 x += 15;
166 } 166 }
174 174
175 int x = 0; 175 int x = 0;
176 for (int i = 0; i < arr_size; i++) { 176 for (int i = 0; i < arr_size; i++) {
177 177
178 // Bottom left 178 // Bottom left
179 glVertex2f(x, OFFSET); 179 glVertex2f(x, VPADDING);
180 180
181 // Top left 181 // Top left
182 glVertex2f(x, arr[i]); 182 glVertex2f(x, arr[i]);
183 183
184 // Top right 184 // Top right
185 glVertex2f(x + RECT_WIDTH, arr[i]); 185 glVertex2f(x + RECT_WIDTH, arr[i]);
186 186
187 // Bottom right 187 // Bottom right
188 glVertex2f(x + RECT_WIDTH, OFFSET); 188 glVertex2f(x + RECT_WIDTH, VPADDING);
189 189
190 x += RECT_WIDTH + SPACE; 190 x += RECT_WIDTH + SPACE;
191 } 191 }
192 192
193 glEnd(); 193 glEnd();
202 render_text(20, WINDOW_HEIGHT - 80, text); 202 render_text(20, WINDOW_HEIGHT - 80, text);
203 203
204 sprintf(text, "Iterations: %i", iter_counter); 204 sprintf(text, "Iterations: %i", iter_counter);
205 render_text(20, WINDOW_HEIGHT - 110, text); 205 render_text(20, WINDOW_HEIGHT - 110, text);
206 206
207 render_text(20, OFFSET - 50, "Press a or s to select an algorithm"); 207 render_text(20, VPADDING - 50, "Press a or s to select an algorithm");
208 render_text(20, OFFSET - 80, "Press enter to run the algorithm"); 208 render_text(20, VPADDING - 80, "Press enter to run the algorithm");
209 render_text(20, OFFSET - 110, "Press r to reset array"); 209 render_text(20, VPADDING - 110, "Press r to reset array");
210 210
211 glutSwapBuffers(); 211 glutSwapBuffers();
212 } 212 }
213 213
214 214
249 algo_selector(-1); 249 algo_selector(-1);
250 } 250 }
251 251
252 // r 252 // r
253 if (key == 114) { 253 if (key == 114) {
254
255 // Reset array
254 create_array(); 256 create_array();
257
258 // Reset state
255 iter_counter = 0; 259 iter_counter = 0;
256 refresh_counter = 0; 260 refresh_counter = 0;
257 run = false; 261 run = false;
262
263 // Reset algo steps
258 bs = (struct BubbleSortInfo){0, 0}; 264 bs = (struct BubbleSortInfo){0, 0};
259 } 265 }
260 266
261 // enter 267 // enter
262 if (key == 13) { 268 if (key == 13) {