This took me far too long, but in my defence it was a long day of regression testing at work: a node.js endpoint which generates a random pixelated image.
The code is reasonably simple: generate a backing 2d array of random values where the probability of there being a pixel is reduced each row. So
n is the number of rows and
x is any row between
The image is then generated, with the usual process of putting 2d coordinates in a single dimension array, with the added fun that each pixel has to take up 4 items in the array (rgba). Thus for any point (x, y) the starting index is
(x + y * width) * 4.
I still have to improve the drop shadow code as it's hacky and buggy, my original thought was to check the alpha of the neighbouring pixels, but I did this in a dumb way and it needs a complete rewrite. Especially the wrapping code.
All in all it was a fun little piece of computer vision programming which takes my website rewrite beyond the default bootstrap theme (oh yeah, I rewrote my main website and used Let's Encrypt everywhere).
Generation of the drop shadow is now there. It uses the backing array rather than the image data, as well as generating offsets and summing then with the current location.