Mercurial > public > algo-animator
annotate README.md @ 30:f945bcc3571f
refactor
author | Dennis C. M. <dennis@denniscm.com> |
---|---|
date | Thu, 29 Jun 2023 17:48:36 +0100 |
parents | 99592fae8ea1 |
children | 61104b22a25d |
rev | line source |
---|---|
4
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
1 # algo-animator |
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
2 |
21 | 3 This project is inspired by - off course - the video by Timo Bingmann called [15 sorting algorithms in 6 minutes](https://www.youtube.com/watch?v=kPRA0W1kECg). |
4 | |
24 | 5  |
26 | 6  |
24 | 7 |
21 | 8 ## Compile |
9 | |
4
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
10 ```bash |
28 | 11 mkdir build |
12 cd build | |
13 cmake .. | |
14 make | |
15 ./algo_animator | |
4
035d3880da04
render text with number of elements on screen
Dennis C. M. <dennis@denniscm.com>
parents:
diff
changeset
|
16 ``` |
21 | 17 |
28 | 18 |
21 | 19 ## To improve |
20 | |
21 Since `GLUT` is single-thread, I cannot call `glutPostRedisplay()` within `while` or `for loops` to redraw the screen in every | |
22 step of the selected sorting algorithm. I guess the solution is multi-threading, so I can perform the sorting in the second thread | |
23 and post notifications to the main thread to redraw the screen. | |
24 | |
25 Since this is my first OpenGL project and just my second program in C, I am tired and I don't want to spend more time in this project, | |
26 but maybe in the future I'll do it. Right now there are just two algorithms supported. I've implemented them in a way that every function | |
27 call is a single step of the sorting. So, storing the "state" outside the function, I can use `idle()` as the loop of the sorting algorithm. | |
28 | |
29 Let's say we selected `bubble sort`. Once you press `ENTER`, the process will be like this: | |
30 | |
31 ```c | |
32 run = true; | |
33 bubble_sort(); | |
34 glutPostRedisplay; | |
35 bubble_sort(); | |
36 glutPostRedisplay; | |
37 bubble_sort(); | |
38 glutPostRedisplay; | |
39 | |
40 // Continue until the array is sorted | |
41 run = false; | |
42 ``` |