> ## Content Index
> Fetch the complete content index at: https://www.oransblog.com/llms.txt
> Use this file to discover other available public pages before exploring further.

# Made a sand simulator
- URL: https://www.oransblog.com/falling-sand-simulator/
- Published: 2024-07-26T15:17:07.000Z
- Updated: 2026-10-29T05:58:14.000Z
- Description: i made this cool sand falling simulator.
- Author: Oran C
- Tags: #Import 2026-11-12 01:14

![](https://www.oransblog.com/content/images/2024/07/image-21.png)

# i made this cool sand falling simulator.

### im proud of the rendering algorithm.

### first time i actually got recursion to work and make it faster!

## normally give up at "max call stack exceeded" :/.

### thank you chat gpt!

## DEMO

# Play the game here!

[falling sand game by wisemonkey -p5.js Web EditorA web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners.![](https://editor.p5js.org/favicon.ico)](https://editor.p5js.org/wisemonkey/sketches/d07oVs7Ws?ref=oransblog.com)

## Dev progress

i saw a developer talk about making a sand falling game.

and realized its just a super cellular automata like simulation! which was super exciting because i just reciently did something similar

[cellular automatai made a program for generating cellular automata![](https://www.oransblog.com/content/images/size/w256h256/2021/04/Front_final_v1_20201118---favicon.png)Oran's BlogOran C![](https://www.oransblog.com/content/images/2024/07/image-7-1.png)](https://www.oransblog.com/cellular-automata/)

I saw the coding description and said i got to make me one of those!

![alt text](https://github.com/wisehackermonkey/falling_sand/raw/main/image.png)

# My progress over time

![](https://www.oransblog.com/content/images/2024/07/image-4-1.png)

mine: got sand falling on the first try\*!

![](https://www.oransblog.com/content/images/2024/07/image-1-1.png)

(\* ) minus some bugs

then got the sand piling beahvor setup

![](https://github.com/wisehackermonkey/falling_sand/raw/main/image-3.png)

tried scaling it up but it was WAY TOO SO.

Here where recursion comes in.

![](https://www.oransblog.com/content/images/2024/07/image-22.png)

# How the algorithm works

![](https://www.oransblog.com/content/images/2024/07/image-23.png)

## create a square test to see if it has any pixels in it.

![](https://www.oransblog.com/content/images/2024/07/image-24.png)

# remove ones with no pixels

![](https://www.oransblog.com/content/images/2024/07/image-25.png)

# keep sub dividing

![](https://www.oransblog.com/content/images/2024/07/image-26.png)

# until you have sufficient accuracy.

# for me it ended up be maxing out at 20 sub divisions

## Speed

# improved the speed from 1 second per draw to 16ms!

![](https://www.oransblog.com/content/images/2024/07/image-27.png)

# thats more like it!

## twittling with settings

![](https://www.oransblog.com/content/images/2024/07/image-28.png)

Draw without borders looks cool

## Quadtree

I think its similar to this thing called a quad tree

![A quadtree.](https://imgs.search.brave.com/MiRy9udE4zWLTXKoivxUyA8ZCtSRUFFAaEfSjonLIVY/rs:fit:860:0:0:0/g:ce/aHR0cHM6Ly9nYW1l/cHJvZ3JhbW1pbmdw/YXR0ZXJucy5jb20v/aW1hZ2VzL3NwYXRp/YWwtcGFydGl0aW9u/LXF1YWR0cmVlLnBu/Zw)

[Quadtree - Wikipedia![](https://en.wikipedia.org/static/apple-touch/wikipedia.png)Wikimedia Foundation, Inc.Contributors to Wikimedia projects![](https://upload.wikimedia.org/wikipedia/commons/thumb/8/8b/Point_quadtree.svg/1200px-Point_quadtree.svg.png)](https://en.wikipedia.org/wiki/Quadtree?ref=oransblog.com)

Just found out what its called when making this writeup. COOL!

i think they have some cool effiancy things

like storing the quadrents as left right nodes of a tree like this. very cool

![Bitmap and its compressed quadtree representation](https://upload.wikimedia.org/wikipedia/commons/thumb/a/a0/Quad_tree_bitmap.svg/380px-Quad_tree_bitmap.svg.png)

![undefined](https://upload.wikimedia.org/wikipedia/commons/thumb/c/c2/2D_Binary_Index.svg/1024px-2D_Binary_Index.svg.png)

# example from Wikipedia

![](https://www.oransblog.com/content/images/2024/07/Quadtree_compression_of_an_image.gif)

## More things you might like!

ant simulator

[ant simulatorantwarfare simulator by wisemonkey -p5.js Web EditorA web editor for p5.js, a JavaScript library with the goal of making coding accessible to artists, designers, educators, and beginners. GitHub - wisehackermonkey/antwarfare: ant game were super colones duke it out for supremacyant game were super c…![](https://www.oransblog.com/content/images/size/w256h256/2021/04/Front_final_v1_20201118---favicon.png)Oran's BlogOran C![](https://www.oransblog.com/content/images/2024/07/image-4--1-.png)](https://www.oransblog.com/ant-sim/)

## Thanks for reading!

![](https://www.oransblog.com/content/images/2021/12/oran.jpg)

# Author

![](https://www.oransblog.com/content/images/2023/08/morse_code_pattern.gif)

by oran collins

Una comparación útil de [equipaciones completas de fútbol](https://www.camisetatienda.com/?ref=oransblog.com) comienza por la correspondencia de medidas entre las piezas. Una revisión final debería incluir si todas las prendas permiten la misma opción de personalización.

![](https://www.oransblog.com/content/images/2023/08/morse_code_pattern.gif)

  
github.com/wisehackermonkey  

![](https://www.oransblog.com/content/images/2021/12/image-16.png)