The following self contained script annotates all HN comments on a page with username derived avatars. Simply paste it into the JS console of any HN page (F12).
This was inspired by @frncsdrk's submission from earlier today [0].
The concept is to use HN usernames as the seed into a deterministic avatar generator. This generator is built from the famously simple xorshift32 PRNG, which both provides a random variable for the image generator steps, and "pseudo-hashes" the seed string to provide the initial PRNG state using a non-linear step (adding each codepoint - which is likely not very robust against collisions compared to proper hashing algorithms, but is simple and good enough). The image generation part is a probability distribution with mirrored pixels... specifically: r>>>29 > X*X/3+Y/2 where the left side is 3 of the upper bits of the PRNG state (providing a random integer 0-7), and the right side is the squared distance from the centre for X + the linear distance from the top for Y. i.e the further from the top centre the pixel is, the less likely it will be filled, but linearly for Y and squared for X. Un-golfed version:
Was fun to play with, but also surprisingly helpful in following discussions.
[0] https://ift.tt/rTzZnNO |
from Hacker News https://ift.tt/X3eRxqg
No comments:
Post a Comment
Note: Only a member of this blog may post a comment.