Veroni Noise



Inspired by news reports of the Corona virus I'm demonstrating how to create a simulation of what looks like cells or viruses under a microscope.
The attached video depicts what may appear to be microscopic organisms running around under a microscope. In Fact this is a bitmap canvas, drawn pixel by pixel, using a method that calculates the color for each pixel based on its distance from set points.
First we separate the canvas into logical rows and columns, creating an invisible grid. Then we select a random point in each tile, which will serve as the tile's reference point.
We then iterate over all the pixels in the canvas, and check each pixel's distance from its nearest reference points. We take the 2 closest points and sum them up to get the total distance from the first point to the pixel to the second point.
We then divide the distance to the closest point from the total distance to get the pixel's current percentage within that distance. Now we have a normalized value that we can color based on a predefined color range- in our case from grey to black. We color each pixel based on it's percentage between the two points - and the result looks like a range of hills colored with gradient colors to determine height.
To make things interesting we need to move our reference points (the ones we set in each tile) as if they are living organisms running around a petri dish.
To do this we run an update function, where we set a random destination point within each tile and ease our reference point towards it.
When the reference point reaches its destination, we pick a new one.
In each frame we run the draw function, iterating over all pixels in the canvas, calculating their nearest reference points, and set their pixel color according to distance percentage.
The attached vidoe depicts what the canvas looks like with 1 cell (not very interesting), 2, 4, 16, 36 and 64 cells.
Hope you enjoyed this post
All source files can be found at:

תגובות

פוסטים פופולריים מהבלוג הזה

Thoughts on HTML5, a Flash Developers hopeless rant

Pseudo 3d Isometric view