java.lang.Object
com.docuverse.identicon.NineBlockIdenticonRenderer2
- All Implemented Interfaces:
IdenticonRenderer
Generates 3x3 geometric identicons from hash codes using symmetric and rotated patch patterns.
Field Summary
FieldsModifier and TypeFieldDescriptionprivate ColorThe background color of the image.private static final int[]The patch shapes allowed in the center.private static final floatDefault patch size, in pixels.private static final byte[]The flags of each patch shape.private static final intPatch shapes per identicon.private static final byteFlag of an inverted patch shape.private static final intPatch coordinate starting a new subpath.private static final byteFlag of a symmetric patch shape.private static final int[][]The patch shape coordinates, by shape.private floatHalf the patch line width, for centering.private GeneralPath[]The scaled shapes of the identicon.private floatThe patch size, in pixels.Constructor Summary
ConstructorsConstructorDescriptionConstructs a renderer with the default patch size.Method Summary
Modifier and TypeMethodDescriptionprivate voiddrawPatch(Graphics2D g, float x, float y, float size, int patch, int turn, boolean invert, Color fillColor, Color strokeColor) Draws one patch of the image.Background color of the identicon.private floatgetColorDistance(Color c1, Color c2) Measures how far apart two colors are.private ColorgetComplementaryColor(Color color) Returns the color opposite on the wheel.floatSize of each patch in the identicon.render(int code, int size) Render an identicon from an integer hash code.render(BigInteger code, int size) Render an identicon from a BigInteger hash code.private BufferedImagerenderQuilt(int code, int size) Draws the nine patch image for a hash code.voidsetBackgroundColor(Color backgroundColor) Set the background color of the identicon.voidsetPatchSize(float size) Set the size for each patch and rebuild the patch shapes.
Field Details
PATCH_GRIDS
DEFAULT_PATCH_SIZE
private static final float DEFAULT_PATCH_SIZEDefault patch size, in pixels.- See Also:
PATCH_SYMMETRIC
private static final byte PATCH_SYMMETRICFlag of a symmetric patch shape.- See Also:
PATCH_INVERTED
private static final byte PATCH_INVERTEDFlag of an inverted patch shape.- See Also:
PATCH_MOVETO
private static final int PATCH_MOVETOPatch coordinate starting a new subpath.- See Also:
PATCH_TYPES
private static final int[][] PATCH_TYPESThe patch shape coordinates, by shape.PATCH_FLAGS
private static final byte[] PATCH_FLAGSThe flags of each patch shape.CENTER_PATCH_TYPES
private static final int[] CENTER_PATCH_TYPESThe patch shapes allowed in the center.patchSize
private float patchSizeThe patch size, in pixels.patchShapes
The scaled shapes of the identicon.patchOffset
private float patchOffsetHalf the patch line width, for centering.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
setBackgroundColor
Set the background color of the identicon.- Parameters:
backgroundColor- the color filled behind the patches
render
Render an identicon from a BigInteger hash code.- Specified by:
renderin interfaceIdenticonRenderer- Parameters:
code- identicon codesize- image size- Returns:
- the rendered image, of exactly
sizebysize
render
Render an identicon from an integer hash code.- Specified by:
renderin interfaceIdenticonRenderer- Parameters:
code- identicon codesize- image size- Returns:
- the rendered image, of exactly
sizebysize
renderQuilt
Draws the nine patch image for a hash code.- Parameters:
code- the hash code driving the patternsize- 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 onx- the left edge of the patchy- the top edge of the patchsize- the patch size, in pixelspatch- the patch shape indexturn- the number of quarter turns to applyinvert- true to draw the inverted colorsfillColor- the color to fill the patch withstrokeColor- the color to outline the patch with
getColorDistance
getComplementaryColor