Game Dev Engine #12. Order from Chaos: Sierpiński Triangle.
2023-10-14. The creation of the Sierpiński Triangle can be done in many ways. One of the coolest is the use of random (chaotic) input, and developing order.
The algorithm could not be more simple:
1. set 3 origin points (or 4 if you're in 3D).
2. initialize a point (to anything, but to avoid artifacts, start at one of the origin points).
3. move 50% the distance to one of the origins (randomly pick one)
4. repeat step 3, drawing the points each time.
This is known as "Order from Chaos" from where I first heard it (yes, I spelled it wrong in the demo, did you notice?). It is also called the "Chaos Game" for generating the fractal from randomness.
I showcase this in 2D and 3D. The rendering in 3D is handled in software on the CPU. No GPU, 4x4 or even 3x3 matrices, involved here (well, I need the GPU to draw the dots!). It uses the core 3D formula that I figured out after many attempts in Grade 8, which is at the root of all perspective correct matrix transforms. I remember thinking with this formula, I could render literally anything... I felt I had discovered the Holy Grail of computer graphics.
The coloring is interesting as well. Each origin has its own color. If the point it at the origin, that color takes 100% of the precedence of the color choice. If the point is equidistant from two origins, then they contribute the same amount.
Interestingly, neither the 2D nor 3D versions have points near the center location of the structure, so you'll never see a color of equal mix of all 4 colors.
Playlists:
--------------
- Xona System 8: https://youtube.com/watch?v=PqFQv60p-0E&list=PLjnbT4UISq0YwheLThIhm3LDxIkwpmKeb
- Voxel: https://youtube.com/watch?v=uadGU-stF-w&list=PLjnbT4UISq0bQF1g85tE9jTrKfEtdRYlY
- Ray Cast: https://youtube.com/watch?v=SkaPYZOKPQg&list=PLjnbT4UISq0YcFtRFjFQqK0g6ONNCtrvY
- Graph-All: https://youtube.com/watch?v=kLSc7bZW2Bs&list=PLjnbT4UISq0YLgynFSpLzml4BMC6TDZL2
- Scroll Shmup: https://youtube.com/watch?v=l9bIYkZepPo&list=PLjnbT4UISq0Y_7IAN_zUzxgZnfhXxo_0Q
- Road: https://youtube.com/watch?v=rA4g4VX7ys8&list=PLjnbT4UISq0bnfd1RC3M4PgTgkmhlkikV
- Arena Shmup: https://youtube.com/watch?v=VKjiuq437t0&list=PLjnbT4UISq0adw__Y9B2eXA0LL35TyORU
- Wave Function: https://youtube.com/watch?v=ngctVd9VK8I&list=PLjnbT4UISq0Y8vYnrSauHkBKgOBHXFFdf
- 3D Polygon: https://youtube.com/watch?v=0Qq_euAMP48&list=PLjnbT4UISq0YyjqBGG8Q34Kng5gqDmYrT
- GW-BASIC: https://youtube.com/watch?v=QMQJ7o8e-GI&list=PLjnbT4UISq0bMjb81xFBIWOLhBKFCVkuB
Websites:
---------------
- GitHub: https://github.com/JDoucette
- Blog: http://thefirstpixel.com
- Studio: http://xona.com