org.gicentre.handy
Class HandyRenderer

java.lang.Object
  extended by org.gicentre.handy.HandyRenderer

public class HandyRenderer
extends java.lang.Object

The renderer that draws graphic primitives in a sketchy style. The style of sketchiness can be configured in this class. Based on an original idea by Nikolaus Gradwohl

Version:
1.0, 28th January, 2012.
Author:
Jo Wood, giCentre, City University London based on an idea by Nikolaus Gradwohl.

Constructor Summary
HandyRenderer(processing.core.PApplet parent)
           
 
Method Summary
 void arc(float x, float y, float width, float height, float start, float stop)
          Draws an arc along the outer edge of an ellipse defined by the x,y, width and height parameters.
 void beginShape()
          Starts a new shape of type POLYGON.
 void beginShape(int mode)
          Starts a new shape of the type specified in the mode parameter.
 void ellipse(float x, float y, float w, float h)
          Draws an ellipse using the given location and dimensions.
 void endShape()
          Ends a shape definition.
 void endShape(int mode)
          Ends a shape definition.
 void line(float x1, float y1, float x2, float y2)
          Draws a 2D line between the given coordinate pairs.
 void point(float x, float y)
          Draws point at the given location.
 void polyLine(float[] xCoords, float[] yCoords)
          Draws a complex line that links the given coordinates.
 void quad(float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
          Draws a quadrilateral shape.
 void rect(float x, float y, float w, float h)
          Draws a rectangle using the given location and dimensions.
 void resetStyles()
          Resets the sketchy styles to default values.
 void setBackgroundColour(int colour)
          Sets the background colour for closed shapes.
 void setFillColour(int colour)
          Sets the fill colour for closed shapes.
 void setFillGap(float gap)
          Determines the gap between fill lines.
 void setFillWeight(float weight)
          Determines the thickness of fill lines.
 void setGraphics(processing.core.PGraphics graphics)
          Sets the the graphics context into which all output is directed.
 void setHachureAngle(float degrees)
          Sets the angle for shading hachures.
 void setHachurePerturbationAngle(float degrees)
          Sets the maximum random perturbation in hachure angle per object.
 void setIsAlternating(boolean alternate)
          Determines whether or not an alternating fill stroke is used to shade shapes.
 void setIsHandy(boolean isHandy)
          Determines whether or not the renderer applies a hand-drawn sketchy appearance.
 void setOverrideFillColour(boolean override)
          Determines whether or not to override the fill colour that would otherwise be determined by the sketch's fillColor setting.
 void setOverrideStrokeColour(boolean override)
          Determines whether or not to override the stroke colour that would otherwise be determined by the sketch's strokeColor setting.
 void setRoughness(float roughness)
          Sets the general roughness of the sketch.
 void setSecondaryColour(int colour)
          Sets the secondary colour for line filling.
 void setSeed(long seed)
          Sets the seed used for random offsets when drawing.
 void setStrokeColour(int colour)
          Sets the stroke colour for rendering features.
 void setStrokeWeight(float weight)
          Determines the thickness of outer lines.
 void setUseSecondaryColour(boolean useSecondary)
          Determines whether or not a secondary colour is used for filling lines.
 void shape(float[] xCoords, float[] yCoords)
          Draws a closed polygon shape based on the given arrays of vertices.
 void shape(float[] xCoords, float[] yCoords, boolean closeShape)
          Draws a polygon shape based on the given arrays of vertices.
static float[] toArray(java.util.List<java.lang.Float> list)
          Converts an array list of numeric values into a floating point array.
 void triangle(float x1, float y1, float x2, float y2, float x3, float y3)
          Draws a triangle through the three pairs of coordinates.
 void vertex(float x, float y)
          Adds a vertex to a shape that was started with a call to beginShape() or one of its variants.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HandyRenderer

public HandyRenderer(processing.core.PApplet parent)
Method Detail

setGraphics

public void setGraphics(processing.core.PGraphics graphics)
Sets the the graphics context into which all output is directed. This method allows output to be redirected to print output, offscreen buffers etc.

Parameters:
graphics - New graphics context in which to render.

setSeed

public void setSeed(long seed)
Sets the seed used for random offsets when drawing. This should be called if repeated calls to the same sketchy drawing methods should result in exactly the same rendering. If not called a vibrating appearance can be given to the rendering.

Parameters:
seed - Random number seed. This can be any whole number, generating the same random variation in rendering on each redraw.

setIsHandy

public void setIsHandy(boolean isHandy)
Determines whether or not the renderer applies a hand-drawn sketchy appearance. If false, normal Processing drawing is used; if true a sketchy appearance using the current configuration style settings is used.

Parameters:
isHandy - Sketchy appearance used if true, or normal Processing appearance if false.

setHachureAngle

public void setHachureAngle(float degrees)
Sets the angle for shading hachures.

Parameters:
degrees - Angle of hachures in degrees where 0 is vertical, 45 is NE-SW and 90 is horizontal.

setHachurePerturbationAngle

public void setHachurePerturbationAngle(float degrees)
Sets the maximum random perturbation in hachure angle per object. This allows a hachure angle to vary between different shapes, but maintain approximate parallel hachure angle within a shape.

Parameters:
degrees - Maximum hachure perturbation angle.

setBackgroundColour

public void setBackgroundColour(int colour)
Sets the background colour for closed shapes.

Parameters:
colour - Background colour.

setFillColour

public void setFillColour(int colour)
Sets the fill colour for closed shapes. Note this will only have an effect if setOverrideFillColour() is true.

Parameters:
colour - Fill colour to use.

setOverrideFillColour

public void setOverrideFillColour(boolean override)
Determines whether or not to override the fill colour that would otherwise be determined by the sketch's fillColor setting. If overridden, the colour is instead chosen from the value last provided to setFillColour().

Parameters:
override - If true the interior colour of features is determined by setFillColour, if not, it is determined by the parent sketch's fill colour setting.

setStrokeColour

public void setStrokeColour(int colour)
Sets the stroke colour for rendering features. Note this will only have an effect if setOverrideStrokeColour() is true.

Parameters:
colour - Stroke colour to use.

setOverrideStrokeColour

public void setOverrideStrokeColour(boolean override)
Determines whether or not to override the stroke colour that would otherwise be determined by the sketch's strokeColor setting. If overridden, the colour is instead chosen from the value last provided to setStrokeColour().

Parameters:
override - If true the stroke colour of features is determined by setStrokeColour, if not, it is determined by the parent sketch's stroke colour setting.

setUseSecondaryColour

public void setUseSecondaryColour(boolean useSecondary)
Determines whether or not a secondary colour is used for filling lines.

Parameters:
useSecondary - If true a secondary colour is used.

setSecondaryColour

public void setSecondaryColour(int colour)
Sets the secondary colour for line filling. Note this will only have an effect if setUseSecondaryColour() is true.

Parameters:
colour - Colour to tint line filling.

setFillWeight

public void setFillWeight(float weight)
Determines the thickness of fill lines. If zero or negative, the thickness is proportional to the sketch's current strokeWeight.

Parameters:
weight - Fill weight in pixel units. If zero or negative, fill weight is based on the sketch's strokeWeight setting.

setStrokeWeight

public void setStrokeWeight(float weight)
Determines the thickness of outer lines. If zero or negative, the thickness is proportional to the sketch's current strokeWeight.

Parameters:
weight - Stroke weight in pixel units. If zero or negative, stroke weight is based on the sketch's strokeWeight setting.

setFillGap

public void setFillGap(float gap)
Determines the gap between fill lines. If zero, standard solid fill is used. If negative, the gap is proportional to the sketch's current strokeWeight.

Parameters:
gap - Gap between fill lines in pixel units. If zero, solid fill used; if negative, gap based on strokeWeight setting.

setIsAlternating

public void setIsAlternating(boolean alternate)
Determines whether or not an alternating fill stroke is used to shade shapes. If true, shading appears as one long zig-zag stroke rather than many approximately parallel lines.

Parameters:
alternate - Zig-zag filling used if true, parallel lines if not.

setRoughness

public void setRoughness(float roughness)
Sets the general roughness of the sketch. 1 is a typically neat sketchiness, 0 is very precise, 5 is very sketchy. Values are capped at 10.

Parameters:
roughness - The sketchiness of the rendering. The larger the number the more sketchy the rendering.

resetStyles

public void resetStyles()
Resets the sketchy styles to default values.


point

public void point(float x,
                  float y)
Draws point at the given location. Currently this draws the point in the same style as the default Processing renderer.

Parameters:
x - x coordinate of the point.
y - y coordinate of the point.

ellipse

public void ellipse(float x,
                    float y,
                    float w,
                    float h)
Draws an ellipse using the given location and dimensions. By default the x,y coordinates will be centre of the ellipse, but the meanings of these parameters can be changed with Processing's ellipseMode() command.

Parameters:
x - x coordinate of the ellipse's position
y - y coordinate of the ellipse's position.
w - Width of the ellipse (but see modifications possible with ellipseMode())
h - Height of the ellipse (but see modifications possible with ellipseMode())

rect

public void rect(float x,
                 float y,
                 float w,
                 float h)
Draws a rectangle using the given location and dimensions. By default the x,y coordinates will be the top left of the rectangle, but the meanings of these parameters can be changed with Processing's rectMode() command.

Parameters:
x - x coordinate of the rectangle position
y - y coordinate of the rectangle position.
w - Width of the rectangle (but see modifications possible with rectMode())
h - Height of the rectangle (but see modifications possible with rectMode())

triangle

public void triangle(float x1,
                     float y1,
                     float x2,
                     float y2,
                     float x3,
                     float y3)
Draws a triangle through the three pairs of coordinates.

Parameters:
x1 - x coordinate of the first triangle vertex.
y1 - y coordinate of the first triangle vertex.
x2 - x coordinate of the second triangle vertex.
y2 - y coordinate of the second triangle vertex.
x3 - x coordinate of the third triangle vertex.
y3 - y coordinate of the third triangle vertex.

quad

public void quad(float x1,
                 float y1,
                 float x2,
                 float y2,
                 float x3,
                 float y3,
                 float x4,
                 float y4)
Draws a quadrilateral shape. Similar to a rectangle but angles not constrained to 90 degrees. Coordinates can proceed in either a clockwise or anti-clockwise direction.

Parameters:
x1 - x coordinate of the first quadrilateral vertex.
y1 - y coordinate of the first quadrilateral vertex.
x2 - x coordinate of the second quadrilateral vertex.
y2 - y coordinate of the second quadrilateral vertex.
x3 - x coordinate of the third quadrilateral vertex.
y3 - y coordinate of the third quadrilateral vertex.
x4 - x coordinate of the fourth quadrilateral vertex.
y4 - y coordinate of the fourth quadrilateral vertex.

arc

public void arc(float x,
                float y,
                float width,
                float height,
                float start,
                float stop)
Draws an arc along the outer edge of an ellipse defined by the x,y, width and height parameters.

Parameters:
x - x coordinate of the start of the line.
y - y coordinate of the start of the line.
width - x coordinate of the end of the line.
height - y coordinate of the end of the line.
start - Angle to start the arc in radians.
stop - Angle to stop the arc in radians.

beginShape

public void beginShape()
Starts a new shape of type POLYGON. This must be paired with a call to endShape() or one of its variants.


beginShape

public void beginShape(int mode)
Starts a new shape of the type specified in the mode parameter. This must be paired with a call to endShape() or one of its variants.

Parameters:
mode - either POINTS, LINES, TRIANGLES, TRIANGLE_FAN, TRIANGLE_STRIP, QUADS, QUAD_STRIP

vertex

public void vertex(float x,
                   float y)
Adds a vertex to a shape that was started with a call to beginShape() or one of its variants.

Parameters:
x - x coordinate of vertex to add.
y - y coordinate of vertex to add.

endShape

public void endShape()
Ends a shape definition. This should have been paired with a call to beginShape() or one of its variants. Note that this version will not close the shape if the last vertex does not match the first one.


endShape

public void endShape(int mode)
Ends a shape definition. This should have been paired with a call to beginShape() or one of its variants. If the mode parameter CLOSE the shape will be closed.


shape

public void shape(float[] xCoords,
                  float[] yCoords)
Draws a closed polygon shape based on the given arrays of vertices.

Parameters:
xCoords - x coordinates of the shape.
yCoords - y coordinates of the shape.

shape

public void shape(float[] xCoords,
                  float[] yCoords,
                  boolean closeShape)
Draws a polygon shape based on the given arrays of vertices. This version can draw either open or closed shapes.

Parameters:
xCoords - x coordinates of the shape.
yCoords - y coordinates of the shape.
closeShape - Boundary of shape will be closed if true.

polyLine

public void polyLine(float[] xCoords,
                     float[] yCoords)
Draws a complex line that links the given coordinates.

Parameters:
xCoords - x coordinates of the line.
yCoords - y coordinates of the line.

line

public void line(float x1,
                 float y1,
                 float x2,
                 float y2)
Draws a 2D line between the given coordinate pairs.

Parameters:
x1 - x coordinate of the start of the line.
y1 - y coordinate of the start of the line.
x2 - x coordinate of the end of the line.
y2 - y coordinate of the end of the line.

toArray

public static float[] toArray(java.util.List<java.lang.Float> list)
Converts an array list of numeric values into a floating point array. Useful for methods that require primitive arrays of floats based on a dynamic collection.

Parameters:
list - List of numbers to convert.
Returns:
Array of floats representing the list.


handy V.1.0, API documentation generated 30th January, 2012