nature-of-code / noc-book-2

The 2024 edition of The Nature of Code with p5.js. Includes Notion workflow and build system.
https://natureofcode.com
1.13k stars 81 forks source link

Particle Automata section #159

Closed sidwellr closed 1 year ago

sidwellr commented 1 year ago

You already have so much to do you probably don't want to add more topics! But Particle CAs mesh so well with the rest of the book topics I thought I should at least suggest it. It's a great solution when you need a particle system that detects collisions but don't want to use a physics library. The technique has been around for years, but it has become popular in the last couple of years with games like Sandspiel and Noita.

Although you could dedicate an entire chapter to Particle CAs, I think all the book really needs is a section in the Cellular Automata chapter to introduce the topic. The section should just explain the basic concept and code a simple falling sand simulation, where each sand particle moves down if it can (i.e., the cell below it contains air); if not it moves diagonally down/left or down/right if one of those cells contains air. Add an exercise to change the sand to water, which behaves the same except that water flows out more than sand so it tries to move straight left or right if it can't move down. Maybe a second exercise to implement both sand and water together (sand sinks in water).

There is a lot more to Particle Automata, but this would at least let readers know they exist and what they do so they can seek out more detailed information if they are interested.

shiffman commented 1 year ago

I think maybe what i'd like to do is have this as a coding challenge video on my youtube channel and maybe reference it as an exercise in the chapter? I'll leave this open as a reminder!

sidwellr commented 1 year ago

Particle CA implementations have some interesting subtleties that may be frustrating if just left as an exercise, but referencing a coding challenge video where you can explain them might work. If you can make the video before finalizing the book, you can decide whether to reference it as an exercise then. Otherwise, I'd leave it out.

shiffman commented 1 year ago

Won't have time to do this before book is finalized but still would like to in the future!!!

https://github.com/CodingTrain/Suggestion-Box/issues/1813