UNPKG

@blockchainhub/blo

Version:

blo is a small and fast library to generate Blockchain identicons.

2 lines (1 loc) 621 B
"use strict";import{seedRandom as a}from"./random.js";const n=2.3,s=40,f=60,i=25;export function image(t,o={}){const{seed:e}=o,r=a(e||t.toLowerCase()),c=randomPalette(r);return[randomImageData(r),c]}export function randomImageData(t){const o=new Uint8Array(32);for(let e=0;e<32;e+=4)o[e]=Math.floor(t()*n),o[e+1]=Math.floor(t()*n),o[e+2]=Math.floor(t()*n),o[e+3]=Math.floor(t()*n);return o}export function randomPalette(t){return{primary:randomColor(t),background:randomColor(t),accent:randomColor(t)}}export function randomColor(t){const o=new Uint16Array(3);return o[0]=t()*360,o[1]=s+t()*f,o[2]=(t()+t()+t()+t())*i,o}