Just click the green flag, and enter turbo mode. You can change the smoothing radius and the number of particles in the code. Also in the code, you can press the f key to see what the sample function looks like. If you want to hide the information, just press enter. To re-show that information, press enter again. Also, if you hover over a dot, it show a cool and funny little bounce animation! This animation even works in turbo mode, as I added a small delay block that only is activated if the frame delay is too small (because in scratch, even waiting 0 seconds actually pauses for a frame, which is undesirable for this satisfying bounce animation lol). Also, each particle’s bounce speed is slightly different, and half of them start at the smallest size, and half at the largest size, both of which hopefully will increase your satisfication! Yay.
This can find the density of any point on the screen by using a function to calculate how much any particular point contributes to the density at that point. The curve for how much it contributes vs. how far it is from the sample point, is a curve, and it smooths out the sampling. But for some reason, there are weird circles with sharp edges, Wat? Help. Anyways, this records a value between 0.0 and 1.0 for each particle. The number that is assigned to the particles is calculated using a random function (that Sebastian Lague used in his video about SPH fluid simulations). Then, let’s pretend that the original function is no longer available (quoting what Sebastian said in his video). Now, we have to estimate the original function using just the values stored in the limited number of points. To do this, we have to let each point contribute to the final value average at any given coordinate, but differently based on their distance to that given coordinate, as the closer it is to that specified coordinate, the more it contributes to the final weighted average. But what is the most important here is that the weighted average keeps the final sum independent of the density. This is achieved by creating a factor, that is based on the distance from a particle to that coordinate, modifying it to be between 0-1, and summing all of those factors together. Then, for each particle, multiply: current particle value, by the fraction: (factor for this particle) / (total factor sum). This means no matter the density in a certain area, the weighted average for that pixel value is kept constant. Also, another useless but satisfying fact about this specific project is that the values for each particle are NOT stored in a list or a variable. Instead, they are stored within the decimal part of the x coordinate of that particle! So to get a value from any particular particle, you have to call that clone, in order for them to provide their x coordinate, and you have to extract only the decimal part by subtracting their x coordinate by their floored x coordinate, and only then can you access their value. What’s so satisfying about this is that you can clear all the variables and all the lists, and still the values are stored within the clones themselves. Technically, you could go a step further and just take a screenshot of the stage, and literally reload the page and extract the decimal part from the anti-aliasing of the bordering pixels of the particle circles in the screenshot! lol. Anyways, have fun!