A simple (and really messy) spirograph visualization project that I've decided to create using CMake, SDL3 and ImGui. It should technically be cross-platform.
Requires SDL3 and SDL_image binaries to function properly.
Inspired by javidx9's spirograph video. (https://www.youtube.com/watch?v=AY99hF3kVH8)
- A spirograph is drawn by having multiple arms rotate at different speeds around an origin point. The rotation speed is defined as the number of rotations per cycle. (1 cycle =
2*pi) - The sum of the polar coordinates of all arm endpoints measured at a given moment in time represents the final spirograph coordinate at that moment.
- Coordinates are measured at evenly spaced intervals based on the amount of points used to render the spirograph and its periodicity. Periodicity refers to the amount of cycles around the origin point required for one end of the graph to intersect the other such that the graph forms a perfect loop.
- Rotation speeds are simplified based on the GCD of all arm rotation speeds.
- The distance between each coordinate is calculated using the formula
2*pi / pointCount * periodicity. Periodicity is equal to the LCM of all arm rotation counts (the number of cycles required for an arm's angle to return to 0 radians at the end of a cycle) - After all the coordinates are calculated, the coordinate array is passed to
SDL_RenderLinesto render the spirograph.
-
Install CMake and a compiler of your choice.
-
If you have git installed, you can clone the project by using the command
git clone https://github.com/TheQwerDev/spirograph-demo.git. If not, you can click the green "Code" button on the GitHub project page. -
In a terminal window,
cdinto the project directory and run the following commands:cmake -S . -B ./buildcmake --build ./build -
If the compiled program doesn't work, place the aforementioned SDL3 binaries into the project build folder.