Article Preview
Buy Now
FEATURE
Sandstorm
Simulating Falling Sand
Issue: 22.1 (January/February 2024)
Author: Marc Zeedar
Author Bio: Marc taught himself programming in high school when he bought his first computer but had no money for software. He's had fun learning ever since.
Article Description: No description available.
Article Length (in bytes): 28,109
Starting Page Number: 44
Article Number: 22105
Resource File(s):
project 22105.zip Updated: 2023-12-31 23:50:57
Related Link(s): None
Excerpt of article text...
Recently I purchased a little "falling sand" desk toy (see Figure 1). I'm a sucker for gizmos like this. I can watch lava swirling or sand falling forever and always find it fascinating.
As I was playing with my new toy, I started wondering if it would be possible to simulate falling sand on my computer. Well, I knew it would be possible—computers can simulate anything with enough data and programming—but I wondered if
I could do it. You see, I'm the opposite of a math wizard and usually simulating physics requires a lot of calculations.Creating Sandstorm
I dove in anyway, launching Xojo and tinkering. Right at the start I decided to do my simulation pixel-for-pixel—in other words, each pixel in a
canvas
would be a grain of sand. After all, grains of sand are tiny, so pixels made sense.I did a
little internet research for algorithms, and as usual much of what I found was overly complicated, designed for video games, and was in other languages that would require understanding them in order to translate the code to Xojo. Though nothing was Xojo-ready, I did get a glimmer of a direction or two and started playing.Already I knew I wasn't going to do anything too complicated. For instance, I would just have regular vertical (down) gravity, not gravity at various angles, and though my desktop toy includes water and air bubbles in the frame that makes the sand swirl and dance in unusual ways (see Figure 2), I wasn't about to try and simulate that!
...End of Excerpt. Please purchase the magazine to read the full article.