UNPKG

@blockchainhub/blo

Version:

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

9 lines (8 loc) 786 B
"use strict";import{randomPalette as d}from"./image.js";import{seedRandom as m}from"./random.js";export const svg=(a,n)=>{const c=m(n.seed||a),{background:r,primary:h,accent:i}=d(c),e=n.size||64,t=e/8,s=new Array(64);for(let $=0;$<32;$++){const o=$%4,g=$/4|0,l=Math.floor(c()*2.3);s[g*8+o]=l,s[g*8+(7-o)]=l}return`<svg xmlns="http://www.w3.org/2000/svg" width="${e}" height="${e}" viewBox="0 0 ${e} ${e}"> <rect width="${e}" height="${e}" fill="hsl(${r[0]},${r[1]}%,${r[2]}%)"/> <g fill="hsl(${h[0]},${h[1]}%,${h[2]}%)"> ${s.map(($,o)=>$===1?`<rect width="${t}" height="${t}" x="${o%8*t}" y="${(o/8|0)*t}"/>`:"").join("")} </g> <g fill="hsl(${i[0]},${i[1]}%,${i[2]}%)"> ${s.map(($,o)=>$===2?`<rect width="${t}" height="${t}" x="${o%8*t}" y="${(o/8|0)*t}"/>`:"").join("")} </g></svg>`};