Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spirograph Demo

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)

How it works

  • 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_RenderLines to render the spirograph.

How to build with CMake

  1. Install CMake and a compiler of your choice.

  2. 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.

  3. In a terminal window, cd into the project directory and run the following commands:

    cmake -S . -B ./build
    
    cmake --build ./build
    
  4. If the compiled program doesn't work, place the aforementioned SDL3 binaries into the project build folder.

Pretty shapes

spiro spiro2 spiro3 spiro4

About

Spirograph visualization demo written in C++ using SDL3 and ImGui

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages