Particles in the Wind
Today’s code example:
This is an example of a particle system: a large number of individual shapes (“particles”) all move independently, but follow the same rules. The total effect of the whole system of particles shows larger patterns and creates an aesthetic effect that is greater than the behavior of each individual particle.
This sketch responds to keypresses. To get the full effect of this sketch, click on the animation (so that you aren’t typing in the code anymore) and then press different keys.
You can start with that full sketch above, but it might be helpful to see it built up step by step:
- Just particles
- Particles + wind
- Particles + wind + keypresses (same link as above)
This is a lot of code, and I do not expect it all to make complete sense — maybe not ever, certainly not within the hour! There are several different ways you could approach this example, and I encourage to choose your own learning and pick whichever of these goals(s) appeal to you:
-
Figure out the effect each piece of code. Even if you can’t make sense of the entire big picture, you can find some parts of the code where you can say “Aha! This does that.” Start by changing different numbers in the code, and see what effect each one has.
-
Identify some building blocks that you could use in your future p5 sketchs. What do you see in the code? Can you figure out what one little piece does, even if the context is mysterious to you?
-
Try to puzzle out what the code does. What rules do the particles follow? What is
windGrid? How does it respond to keypresses? How does this sketch work?? -
Make something cool. This is always a goal in this class. Try mixing it up. Make some changes. If you come up with something awesome, share it!