blo
Version:
blo is a small and fast library to generate Ethereum identicons.
33 lines (32 loc) • 944 B
JavaScript
import { randSeed, nextRandom } from "./random.js";
function image(address) {
const rseed = randSeed(address.toLowerCase());
const c = randomColor(rseed);
const b = randomColor(rseed);
const s = randomColor(rseed);
const data = new Uint8Array(32);
for (let i = 0; i < 32; i++) {
data[i] = Math.floor(
// background: 43% chances
// color: 43% chances
// spot: 13% chances
nextRandom(rseed) * 2.3
);
}
return [data, [b, c, s]];
}
function randomColor(rseed) {
return new Uint16Array([
// hue = 0 to 360 (whole color spectrum)
nextRandom(rseed) * 360,
// saturation = 40 to 100 (avoid greyish colors)
40 + nextRandom(rseed) * 60,
// lightness = 0 to 100 but probabilities are a bell curve around 50%
(nextRandom(rseed) + nextRandom(rseed) + nextRandom(rseed) + nextRandom(rseed)) * 25
]);
}
export {
image,
randomColor
};
//# sourceMappingURL=image.js.map