java.lang.Object
com.docuverse.identicon.NineBlockIdenticonRenderer2
All Implemented Interfaces:
IdenticonRenderer

public class NineBlockIdenticonRenderer2extends Object implements IdenticonRenderer
Generates 3x3 geometric identicons from hash codes using symmetric and rotated patch patterns.
  • Field Details

    • PATCH_GRIDS

      private static final int PATCH_GRIDS
      Patch shapes per identicon.
      See Also:
    • DEFAULT_PATCH_SIZE

      private static final float DEFAULT_PATCH_SIZE
      Default patch size, in pixels.
      See Also:
    • PATCH_SYMMETRIC

      private static final byte PATCH_SYMMETRIC
      Flag of a symmetric patch shape.
      See Also:
    • PATCH_INVERTED

      private static final byte PATCH_INVERTED
      Flag of an inverted patch shape.
      See Also:
    • PATCH_MOVETO

      private static final int PATCH_MOVETO
      Patch coordinate starting a new subpath.
      See Also:
    • PATCH_TYPES

      private static final int[][] PATCH_TYPES
      The patch shape coordinates, by shape.
    • PATCH_FLAGS

      private static final byte[] PATCH_FLAGS
      The flags of each patch shape.
    • CENTER_PATCH_TYPES

      private static final int[] CENTER_PATCH_TYPES
      The patch shapes allowed in the center.
    • patchSize

      private float patchSize
      The patch size, in pixels.
    • patchShapes

      private GeneralPath[] patchShapes
      The scaled shapes of the identicon.
    • patchOffset

      private float patchOffset
      Half the patch line width, for centering.
    • backgroundColor

      private Color backgroundColor
      The background color of the image.
  • Constructor Details

    • NineBlockIdenticonRenderer2

      public NineBlockIdenticonRenderer2()
      Constructs a renderer with the default patch size.
  • Method Details

    • getPatchSize

      public float getPatchSize()
      Size of each patch in the identicon.
      Returns:
      the patch size
    • setPatchSize

      public void setPatchSize(float size)
      Set the size for each patch and rebuild the patch shapes.
      Parameters:
      size - the edge length in pixels of one patch of the 3x3 grid
    • getBackgroundColor

      public Color getBackgroundColor()
      Background color of the identicon.
      Returns:
      the background color
    • setBackgroundColor

      public void setBackgroundColor(Color backgroundColor)
      Set the background color of the identicon.
      Parameters:
      backgroundColor - the color filled behind the patches
    • render

      public BufferedImage render(BigInteger code, int size)
      Render an identicon from a BigInteger hash code.
      Specified by:
      render in interface IdenticonRenderer
      Parameters:
      code - identicon code
      size - image size
      Returns:
      the rendered image, of exactly size by size
    • render

      public BufferedImage render(int code, int size)
      Render an identicon from an integer hash code.
      Specified by:
      render in interface IdenticonRenderer
      Parameters:
      code - identicon code
      size - image size
      Returns:
      the rendered image, of exactly size by size
    • renderQuilt

      private BufferedImage renderQuilt(int code, int size)
      Draws the nine patch image for a hash code.
      Parameters:
      code - the hash code driving the pattern
      size - the image size, in pixels
      Returns:
      the image drawn
    • drawPatch

      private void drawPatch(Graphics2D g, float x, float y, float size, int patch, int turn, boolean invert, Color fillColor, Color strokeColor)
      Draws one patch of the image.
      Parameters:
      g - the graphics to draw on
      x - the left edge of the patch
      y - the top edge of the patch
      size - the patch size, in pixels
      patch - the patch shape index
      turn - the number of quarter turns to apply
      invert - true to draw the inverted colors
      fillColor - the color to fill the patch with
      strokeColor - the color to outline the patch with
    • getColorDistance

      private float getColorDistance(Color c1, Color c2)
      Measures how far apart two colors are.
      Parameters:
      c1 - the first color
      c2 - the second color
      Returns:
      the distance, larger for more different
    • getComplementaryColor

      private Color getComplementaryColor(Color color)
      Returns the color opposite on the wheel.
      Parameters:
      color - the color to complement
      Returns:
      the complementary color