Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 21 in printed book and digital formats -- plus a one-year subscription (beginning with 22.1) so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview

Buy Now

Issue 22.1 ('Sandstorm')
Instant purchase and download via GumRoad!



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):

Download Icon 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.