JavaScript variant of GitHub Identicons
class Identicon
(options [optional] object
)
-
color
string
[optional] -
backgroundColor
string
[optional] -
seed
string
[optional] (String of any length to set a specific color forcolor
. For example the seed "Test" will always set the color to green.)
You don't have to set the colors in the constructor. You can always change them by setting the attributes after the initialization of the object.
-
grid
- Internal representation of the icon as a two dimensional array.
-
color
- Color of the icon as a css color. Default
green
.
- Color of the icon as a css color. Default
-
backgroundColor
- Color of the icon as a css color. Default
transparent
.
- Color of the icon as a css color. Default
-
render()
- Icon as SVG string.
-
randomize()
- Sets new random pattern to
grid
. Returns therender()
Method.
- Sets new random pattern to
const Identicon = require('./src/identicon.js');
let image = new Identicon({color: "purple", backgroundColor: "white"});
console.log(image.render());
For web browser usage, use as commonJS module or remove module.exports = Identicon;
from the JS file and use it like a regular class.
Then use
let image = new Identicon();
console.log(image.render());
// Set new color and new random image
image.color = "#e61c1c";
icon.randomize();
console.log(image.render());