HN Avatars in 396 bytes

Annotated avatars on all HN comments.

Δημιουργός
libele
Ημερήσιες εγκαταστάσεις
0
Σύνολο εγκαταστάσεων
62
Βαθμολογίες
1 0 0
Έκδοση
1.0.6
Δημιουργήθηκε την
15/03/2022
Ενημερώθηκε την
18/09/2022
Μέγεθος
1 KB
Συμβατότητα
Συμβατό με Firefox Συμβατό με Chrome Συμβατό με Opera Συμβατό με Edge
Άδεια
Μη διαθέσιμη
Εφαρμόζεται σε

HN Avatars in 357 bytes by tomxor

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).

Golfed version, prettified to comply with GreasyFork rules. Thanks to chrismorgan, hawski, toqy and z3c0 for additions!

for(u of document.querySelectorAll('.hnuser,#me'))for(u.prepend(c=document.createElement('canvas')),x=c.getContext('2d'),c.width=18,c.height=14,c.style.imageRendering='pixelated',s=u.innerText,r=1,i=28+s.length;i--;i<28?r>>>29>X*X/3+Y/2&&x.fillRect(6+2*X,2*Y,2,2)&x.fillRect(6-2*X,2*Y,2,2):r+=s.charCodeAt(i-28,x.fillStyle='#'+(r>>8&0xFFFFFF).toString(16)))r^=r<<13,r^=r>>>17,r^=r<<5,X=i&3,Y=i>>2