Date: 03-12-2019
Click here to visit on P5 Web Editor
Personally, I really liked this week’s topic, because it begins to reveal the essence of the course name! What I did after class this week is similar to what we did in class. It has the wind method controlled by mouse X position, and buoyancy based on Y position. I also added a few other features to make it more interesting.
Besides water, I added an oil layer, whose density is smaller than water, so it floats above water. Thus there are three possible states for a particle: floating on oil, floating under oil and on water, and staying at the bottom of water. Which state a particle is in is determined by its density, which is why I added density to each particle. It is a random value, just like the size of each particle. Now that we have both size and density, we can calculate its mass by simply multiplying them (technically, mass = density * volume, and sphere volume = 0.75 * pi * radius cube, so if I were to be accurate, it would be m = ρ * 0.75 * pi * (size / 2) ^ 3. But here I omitted the complicated calculations). Then I added colors to the particles to indicate the density of each of them, using the map() function. The lighter the color, the smaller the density.