In this article, I will be talking about Fourier series and epicycles (Foucycle), seemingly two distinct branches of mathematics if you're unaware of Euler's famous formula.
Epicycles are essentially circles within circles, they have
been studied extensively by astronomers because it was thought planets' motion was perfectly circular (Not to mention how they were convinced the earth
was the centre of the universe) until the inverse-square law of planet motion
was introduced by Keppler and Newton. Fourier series is essentially a way to approximate any function as the infinite sum of scaled sins and cosines, simple yet revolutionary.
As always, 3Blue1Brown produced an amazing video on Fourier art which, to be honest, inspired this article. I won't dive into explaining
the mathematics behind how this all works because there are plenty of materials online. I have created a python library based on the work of this repository that makes it easy for anyone using python to generate beautiful epicycles of any picture they want! (Well, nearly).
How to generate Fourier art
First, make sure you have anaconda installed, then create a new environment
conda create -n epicycle python==3.8
conda activate epicycle
Then make sure ffmpeg library is installed to create the videos
conda install -c conda-forge ffmpeg
Lastly, download the library I have created using pip, all the dependencies will be automatically installed:
pip install photoepicycle
And we are done! To test it, download the test picture in the example and save it in a place you know well. Then run the library as a script.
python -m picycle -p /path/to/your/picture.jpg
and voila! you should get a video like below on the same path and the following message:
completed: epicycle.mp4
Done
What not to try
By far, the hardest part is extracting traceable edges of the uploaded picture. The code works well with silhouette images, and that's about it. Trying to create a traceable path of photographs quickly turns into a travelling salesman problem, which is expensive even for sub-optimal solutions.
Comments
Post a Comment