Jazzicon

repository·master·Indexed 42 days ago

https://github.com/danfinlay/jazzicon

A library for generating colorful, collage-style identicons based on integer seeds. It provides functions like jazzicon() and generateIdenticon() to create deterministic, 80s-inspired SVG visual representations as DOM elements.

Tokens
561
Snippets
4
Records
4
Agent score
3%

What's inside Jazzicon

  1. Use the jazzicon function to generate identicons

    master

    The jazzicon function generates a colorful, collage-style identicon as a DOM element. It requires two arguments:

    1. diameter (Number): The pixel diameter of the generated icon.
    2. seed (Integer): A JavaScript integer used to seed the shape of the icon.

    The function returns a DOM element that can be appended directly to the document.

    var jazzicon = require('jazzicon')
    
    // Generate an icon with 100px diameter and a random seed
    var el = jazzicon(100, Math.round(Math.random() * 10000000))
    
    // Use the returned DOM element
    document.body.appendChild(el)
  2. Generate an identicon with generateIdenticon()

    master

    The generateIdenticon function creates a DOM element containing an SVG identicon. The visual output is determined by a diameter and a seed integer. The function uses a Mersenne Twister PRNG seeded with your input to ensure that the same seed always produces the same visual pattern.

    Parameters:

    • diameter (Number): The width and height of the resulting SVG in pixels.
    • seed (Integer): An integer used to seed the random number generator, ensuring deterministic output.

    Returns:

    • HTMLElement: A container element (generated via paperGen) containing the constructed <svg> and its shape elements.
    const generateIdenticon = require('jazzicon');
    
    // Generate a 100px identicon using seed 12345
    const identicon = generateIdenticon(100, 12345);
    
    // Append it to the document
    document.body.appendChild(identicon);