Very simple falling sand simulation

Show off your games, demos and other (playable) creations.
Post Reply
whateverest
Prole
Posts: 3
Joined: Fri Sep 29, 2023 6:46 pm

Very simple falling sand simulation

Post by whateverest »

A few weeks back I stumbled across one of this falling sand simulations on the web and wondered how hard it would be to implement this.
Turns out it is very simple, the rules for the falling sand for example are implemented with only 10 lines!

Writing it was really fun - I haven't used löve/lua for years. Playing around with it is surprisingly fun too so I decided to share it here.
screenshot.png
screenshot.png (17.49 KiB) Viewed 12744 times
Considering that I did not spend a lot of time on it I am pretty happy with the result.
The only type of cell that I am not quite happy with is the water. Sometimes it behaves kinda weird and the implementation seems unnecessarily complex.

7 Types of cells are implemented. You can select them by using the number keys and you can "draw" the cells by left clicking.
  1. Sand
  2. Water
  3. (Floating ;)) Concrete
  4. Plants - Grows to nearby cells until a certain height is reached
  5. Eraser - Deletes cells
  6. Fire - Spreads to and consumes nearby plants. Spawns Smoke Above itself
The code is not object oriented, which fit this project quite well i think. Currently the field has only 200 x 130 cells, but I think the simulation should be able to handle much larger areas.

The source code can be found here: https://codeberg.org/ycake/sandsimulation.
Attachments
sandsimulation.love
(3.64 KiB) Downloaded 106 times
Last edited by whateverest on Fri Oct 13, 2023 10:10 pm, edited 3 times in total.
User avatar
dusoft
Party member
Posts: 510
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Very simple falling sand simulation

Post by dusoft »

Nice sandbox!
User avatar
togFox
Party member
Posts: 779
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Very simple falling sand simulation

Post by togFox »

This is really cool. You should find a way to export the result and then make it a side scrolling map like Terrairia or something.

"Jake - look at this - I sprinkled all this stuff everywhere then exported and started jumping around it and explored this thing that is mine. I'm going to do that again and see how whacky I can make it. "

8-)
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
User avatar
knorke
Party member
Posts: 239
Joined: Wed Jul 14, 2010 7:06 pm
Contact:

Re: Very simple falling sand simulation

Post by knorke »

Nice project.
Small problem, the window does not fully fit on my laptop's screen.
User avatar
BrotSagtMist
Party member
Posts: 615
Joined: Fri Aug 06, 2021 10:30 pm

Re: Very simple falling sand simulation

Post by BrotSagtMist »

But o gosh the cpu usage :D
I actually love this kind of simulations, now ad stuff that acts automous, cows that eat the grass, fish that swim in the water, b2 bombers that drop poop bombs from the sky.
obey
whateverest
Prole
Posts: 3
Joined: Fri Sep 29, 2023 6:46 pm

Re: Very simple falling sand simulation

Post by whateverest »

knorke wrote: Sat Sep 30, 2023 5:37 pm Nice project.
Small problem, the window does not fully fit on my laptop's screen.
Thanks!
The Window should be resizable but that obviously does not help too much if the simulation area does not fit on the screen anyway.
Maybe I get around to adding a very basic zoom function sometime.
BrotSagtMist wrote: Sat Sep 30, 2023 10:25 pm But o gosh the cpu usage :D
I actually love this kind of simulations, now ad stuff that acts automous, cows that eat the grass, fish that swim in the water, b2 bombers that drop poop bombs from the sky.
Runs fine on my machine :crazy: But true, performance optimization is not something I too much thought into and I probably won't for this small fun-project :).

Yeah I love how much cool behavior you can get with very simple rules. You could probably add endless amount of new cell types.
User avatar
GVovkiv
Party member
Posts: 670
Joined: Fri Jan 15, 2021 7:29 am

Re: Very simple falling sand simulation

Post by GVovkiv »

whateverest wrote: Sun Oct 01, 2023 5:41 pm
Thanks!
The Window should be resizable but that obviously does not help too much if the simulation area does not fit on the screen anyway.
Maybe I get around to adding a very basic zoom function sometime.
There, in fact, several libraries that could scale game content to any window size, which might help with this task.
This libraries in semi-active to barely active states
https://github.com/Vovkiv/resolution_solution
https://github.com/Ulydev/push
https://github.com/S-Walrus/center

While this libraries is abandoned
https://github.com/adekto/maid64
https://github.com/tomlum/simpleScale
User avatar
togFox
Party member
Posts: 779
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Very simple falling sand simulation

Post by togFox »

Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
whateverest
Prole
Posts: 3
Joined: Fri Sep 29, 2023 6:46 pm

Re: Very simple falling sand simulation

Post by whateverest »

Thanks for the suggestions!

In the end i went with a very simple zoom function using the mouse wheel though. That should make the program at least usable on smaller screens.
The last thing I would like to add, before I'll probably abandon the project, would be to make the simulation size configurable so it doesn't melt peoples PCs :) .
User avatar
BrotSagtMist
Party member
Posts: 615
Joined: Fri Aug 06, 2021 10:30 pm

Re: Very simple falling sand simulation

Post by BrotSagtMist »

Havnt looked at your code but from own simulations i found skipping works really well.
Eg work only even objects one frame and uneven the next, behaves almost the same but instant halves cpu usage.
obey
Post Reply

Who is online

Users browsing this forum: No registered users and 63 guests