Why I Love Algorithms
I have always loved algorithms. They let me take something ephemeral akin to math and turn it into an almost living thing, like a bouncing ball on a computer screen or a compressed image file. I especially like algorithms you can use to create something visual.
Some particularly visually striking algorithms are those for fractals.
An example of how neat something a simple algorithm can create is the Koch snowflake. This curve was first created (or discovered) by mathematician Helge von Koch and published in a 1904 paper. .
This animation from the Wikipedia page about the Koch snowflake, graciously placed into the public domain by its creator, António Miguel de Campos, shows the Koch snowflake fractal curve through the first seven iterations.
And to give you a more living example of this you can run some code to generate a Koch curve yourself on repl.it which is a site where you can write, run, and share code online.
Look at the implementation of the Koch snowflake at this link: https://replit.com/@RichardAnton/MyKochSnowflake
This code uses recursion, which is when a function in a program calls itself. In this case, the function calls itself to make increasingly smaller aspects of the curve, which is kind of the essence of the idea of a fractal. A fractal repeats itself at different scales. This is called self-similarity.
Go there, try it out, and then play around with the code at the bottom to change the size, position, and colors of the snowflakes.
If you want to see the most famous fractal, the Mandelbrot set, and explore just how endlessly it keeps going, then visit Xaos where you can zoom in online as deep as you like. Here’s a sample of a random tiny bit of the Mandelbrot set.
You can also check out a C++ viewer of the Mandelbrot set I coded at https://github.com/ranton256/mandelbrot-sdl2 which I used to the screenshot below.
Another fun fractal curve to play around with is the Dragon curve. You can find lots of example implementations of this one at https://rosettacode.org/wiki/Dragon_curve. Check out this repl.it with one of the code samples from there: https://replit.com/@RichardAnton/MyDragonCurve
This is a fancier version of the same curve built using a color C++ implementation.
References and Credits
- The animation Koch snowflake GIF is by António Miguel de Campos - self made based in own JAVA animation, Public Domain, https://commons.wikimedia.org/w/index.php?curid=2110722
- Von Koch, Helge. “On a Continuous Curve without Tangents Constructive from Elementary Geometry.” In Classics on fractals, pp. 24-45. CRC Press, 2019.
- https://en.wikipedia.org/wiki/Self-similarity
- https://en.wikipedia.org/wiki/Mandelbrot_set
- https://en.wikipedia.org/wiki/Dragon_curve
- https://rosettacode.org/wiki/Dragon_curve
- https://mathworld.wolfram.com/DragonCurve.html