Module

Completion

Progress 5/5
5/5

Completion & Discussion Checklist

Before joining the group discussion or concluding this tutorial, ensure you have completed the tasks, investigated the bugs, and are ready to discuss the questions below:

Click to expand Completion & Discussion Checklist (11 Items)
#TypeItemPrompt Preview
1Bug HuntEmpty Grid Null CheckThe code we just added has an error. grid uses null to represent empty spaces. This will cause an error when we try to access particle.color because particle is null.
2Bug HuntVanishing Water Swap BugRun the simulation, create a pool of water, and drop sand particles on top of it. Notice anything strange? The sand falls through, but the water completely vanishes into thin air instead of rising to the surface!
3TaskImplement checkBounds()Modify the checkBounds function so it returns true if (row, col) is within the bounds of grid and false otherwise. After writing the function, use it in moveParticle to prevent particles from being moved out of bounds.
4TaskFix Particle StreakingModify the moveParticle function in canvas.js to stop the particles from streaking as they fall.
5TaskPrevent Particle OverwriteUtilizing getParticle (which returns the particle at (row, col)), add a check in the moveParticle function in canvas.js to make sure a particle cannot move on top of another particle.
6TaskWater Movement VariationsMess around with water physics! Change the probabilities of movement, add extra movement options, make floating water, or add a random chance to teleport to a random location. Add 3 new behaviors to water’s update function.
7TaskCreate Stone ClassCreate a new class called Stone that extends the Particle class. In its constructor, set the color to "gray" and the type to "stone". Make sure to add Stone as an option in checkParticleType.
8TaskCreate Dirt ClassCreate a new class called Dirt that extends the Sand class. In its constructor, set the color to "brown" and the type to "dirt". Make sure to add Dirt as an option in checkParticleType.
9TaskCreate Grass ClassCreate a new class called Grass in particles.js that extends the Sand class. In its constructor, set the color to "green" and the type to "grass". Grass can ONLY be created when water touches dirt.
10ChallengeCustom Physics ExperimentationMess around with the sand physics! What happens if you have the sand move two steps every update (row+2 or col+2), or if you try to move left and right first?
11Challenge3 Custom ParticlesAdd at least 3 new particles and make sure to add interactions with other particles (don’t just add Metal and make it act like Stone). Get creative with it!

Congratulations!

You’ve now taken your Falling Sand simulation to the next level! In this second part of the tutorial, you’ve successfully:

  • Introduced a new particle type, Water, and implemented its unique physics, including random movement and interactions with other particles.
  • Utilized the getRandomInt() function to add probabilistic behavior to your particles, making the simulation more dynamic and realistic.
  • Implemented the swap() function to create interactions between different particle types, allowing Sand to fall through Water.
  • Added Stone and Dirt particles, demonstrating how to extend existing classes and create new particle behaviors.
  • Created a dynamic interaction between Water and Dirt, resulting in the creation of Grass, showcasing the power of particle interactions.
  • Further expanded your understanding of JavaScript classes, inheritance, and object-oriented programming.
  • Practiced your problem-solving and debugging skills by experimenting with particle behaviors.

You’ve built a solid foundation for creating even more complex and interesting particle simulations. Now, let’s explore how you can further expand your project with new particles and interactions!