Mercurial > public > algo-animator
annotate utils.c @ 6:40a8bdbe2005
Refactor to array of structures
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Tue, 13 Jun 2023 18:37:23 +0100 |
parents | 6be2faa7ed6e |
children | f159eec07daf |
rev | line source |
---|---|
4
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
1 #include "utils.h" |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
2 |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
3 |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
4 void render_text(const char *text, float x, float y) { |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
5 glRasterPos2f(x, y); |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
6 |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
7 for (const char *c = text; *c; ++c) { |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
8 glutBitmapCharacter(GLUT_BITMAP_TIMES_ROMAN_24, *c); |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
9 } |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
10 } |
5
6be2faa7ed6e
rectangles with variable height
Dennis C. M. <dennis@denniscm.com>
parents:
4
diff
changeset
|
11 |
6be2faa7ed6e
rectangles with variable height
Dennis C. M. <dennis@denniscm.com>
parents:
4
diff
changeset
|
12 |
6be2faa7ed6e
rectangles with variable height
Dennis C. M. <dennis@denniscm.com>
parents:
4
diff
changeset
|
13 int random_int(int min, int max) { |
6be2faa7ed6e
rectangles with variable height
Dennis C. M. <dennis@denniscm.com>
parents:
4
diff
changeset
|
14 return rand() % ((max - min) + 1) + min; |
6be2faa7ed6e
rectangles with variable height
Dennis C. M. <dennis@denniscm.com>
parents:
4
diff
changeset
|
15 } |
6
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
16 |
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
17 |
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
18 void draw_rectangle(int x_position, int rect_height, int rect_width, int window_height) { |
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
19 glVertex2f(x_position, window_height - 100); |
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
20 glVertex2f(x_position + rect_width, window_height - 100); |
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
21 glVertex2f(x_position + rect_width, rect_height); |
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
22 glVertex2d(x_position, rect_height); |
40a8bdbe2005
Refactor to array of structures
Dennis C. M. <dennis@denniscm.com>
parents:
5
diff
changeset
|
23 } |