Class PABezShape
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) float[]left, top, right, bottom bounding rectanglestatic final intflag for curve segment type, associated with PauBezVertexprivate ArrayList<PAVertex2DINF>list of bezier vertices(package private) intfill color for shape(package private) booleanflags if shape is filled or not(package private) booleanflags if shape has a stroke or not(package private) booleanflags if shape is closed or not(package private) booleanflags we should draw control points and verticesstatic final doubleIn the approximation of a circle by Bezier curves,
KAPPA = (distance between Bezier anchor and its associated control point) / (circle radius),
when a circle is divided into 4 sectors of 90 degrees.
KAPPA = 4 * (√2 - 1) / 3 = 0.5522847498static final floatA value for weighting Bezier splines based on the length of line segments between anchor points, derived from the ratio of the chord of a quarter circle to KAPPA.static final intflag for line segment type, associated with LineVertex(package private) intstroke color for shape(package private) floatstroke weight for shape(package private) floatinitial x-coordinate(package private) floatinitial y-coordinate -
Constructor Summary
ConstructorsConstructorDescriptionPABezShape(float x, float y, boolean isClosed) Creates a BezShape with initial point x,y, closed or open according to the value of isClosed. -
Method Summary
Modifier and TypeMethodDescriptionvoidappend(float x, float y) Appends a LineVertex (line segment) to this BezShape.voidappend(float cx1, float cy1, float cx2, float cy2, float x, float y) Appends a PauBezVertex (cubic Bezier segment) to this BezShape.voidappend(PAVertex2DINF vt) Appends a Vertex2DINF to this BezShapestatic int[]argbComponents(int argb) Breaks a Processing color into A, R, G and B values in an array.floatbezierPoint(float a, float b, float c, float d, float t) Evaluates the Bezier at point t for points a, b, c, d.floatbezierTangent(float a, float b, float c, float d, float t) Calculates the tangent of a point on a Bézier curve.protected float[]bounds()Calculates the boundary rectangle of this shape and returns it as an array of floats.clone()Creates a deep copy of this BezShape.static intcomposeColor(int gray) Creates a Processing ARGB color from a grayscale value.static intcomposeColor(int[] comp) Creates a Processing ARGB color from r, g, b, values in an array.static intcomposeColor(int r, int g, int b) Creates an opaque Processing RGB color from r, g, b values.static final intcomposeColor(int r, int g, int b, int a) Creates a Processing ARGB color from r, g, b, and alpha channel values.Returns an iterator over the geometry of this shape.voiddraw(processing.core.PApplet parent) Draws this shape to the display.voiddraw(processing.core.PGraphics pg) Draws this shape to an offscreen PGraphics.voiddrawQuick(processing.core.PApplet parent) Draws this shape to the display.voiddrawQuick(processing.core.PGraphics pg) Draws this shape to a PGraphics passed as an argument.intintfloat[]processing.core.PVectorArrayList<processing.core.PVector>getPointList(int steps) Extracts an approximated polygon from path data, returning it as an array of PVector.ArrayList<processing.core.PVector>getPointList(processing.core.PApplet parent, int steps) Deprecated.ArrayList<processing.core.PVector>getPointList(processing.core.PGraphics pg, int steps) Deprecated.booleanhasFill()booleanbooleanisClosed()booleanisMarked()intReturns number of points (anchor points and control points) in curves.static booleanpointInPoly(ArrayList<processing.core.PVector> poly, float x, float y) Decides if a point is inside a polygon, returns true if it is.static int[]rgbaComponents(int argb) Breaks a Processing color into R, G, B and A values in an array.static int[]rgbComponents(int rgb) Breaks a Processing color into R, G and B values in an array.static processing.core.PVectorrotateCoordAroundPoint(float x, float y, float xctr, float yctr, float theta) Rotates a point theta radians around a point (xctr, yctr), returns a new point.voidrotateShape(float xctr, float yctr, float theta) Rotates this shape around a supplied center point.static processing.core.PVectorscaleCoordAroundPoint(float x, float y, float xScale, float yScale, float xctr, float yctr) Scales a point by xScale and yScale around a point (xctr, yctr), returns a new point.voidscaleShape(float xScale, float yScale, float x0, float y0) Scales this shape around a given point.voidsetBounds(float[] newBounds) voidsetFillColor(int newFillColor) voidsetFillOpacity(int opacity) Sets opacity of current fill color.voidsetHasFill(boolean newHasFill) voidsetHasStroke(boolean newHasStroke) voidsetIsClosed(boolean newIsClosed) voidsetIsMarked(boolean newIsMarked) voidMarks this component as having no fill.voidMarks this component as having no stroke Equivalent to setHasStroke(false), if the implementor provides a setHasStroke methodvoidsetStartPoint(float newX, float newY) Sets a new initial vertex for this BezShape.voidsetStrokeColor(int newStrokeColor) voidsetStrokeOpacity(int opacity) Sets opacity of current stroke color.voidsetWeight(float newWeight) voidsetX(float newX) Sets the x-coordinate of the initial point of the geometry of this shape.voidsetY(float newY) Sets the y-coordinate of the initial point of the geometry of this shape.intsize()Returns size of number of vertices (PauBezVertex and LineVertex) in curves.intintstatic processing.core.PVectortranslateCoord(float x, float y, float xOffset, float yOffset) Translates a point by xOffset and yOffset, returns a new point.voidtranslateShape(float xTrans, float yTrans) Translates this shape in x and y directions.floatweight()Returns the current weight (in points) of stroked lines.floatx()Returns the x-coordinate of the initial point of the geometry of this shape.floaty()Returns the y-coordinate of the initial point of the geometry of this shape.
-
Field Details
-
x
float xinitial x-coordinate -
y
float yinitial y-coordinate -
curves
list of bezier vertices -
isClosed
boolean isClosedflags if shape is closed or not -
isMarked
boolean isMarkedflags we should draw control points and vertices -
LINE_SEGMENT
public static final int LINE_SEGMENTflag for line segment type, associated with LineVertex- See Also:
-
CURVE_SEGMENT
public static final int CURVE_SEGMENTflag for curve segment type, associated with PauBezVertex- See Also:
-
hasFill
boolean hasFillflags if shape is filled or not -
hasStroke
boolean hasStrokeflags if shape has a stroke or not -
fillColor
int fillColorfill color for shape -
strokeColor
int strokeColorstroke color for shape -
weight
float weightstroke weight for shape -
bounds
float[] boundsleft, top, right, bottom bounding rectangle -
KAPPA
public static final double KAPPAIn the approximation of a circle by Bezier curves,
KAPPA = (distance between Bezier anchor and its associated control point) / (circle radius),
when a circle is divided into 4 sectors of 90 degrees.
KAPPA = 4 * (√2 - 1) / 3 = 0.5522847498 -
LAMBDA
public static final float LAMBDAA value for weighting Bezier splines based on the length of line segments between anchor points, derived from the ratio of the chord of a quarter circle to KAPPA. LAMBDA = KAPPA * (1/√2) = 0.39052429175f- See Also:
-
-
Constructor Details
-
PABezShape
public PABezShape(float x, float y, boolean isClosed) Creates a BezShape with initial point x,y, closed or open according to the value of isClosed. Fill, stroke, and weight of shapes are set from their values in the Processing environment. The Processing transformation matrix (set by calls to rotate, translate and scale) is saved to the instance variablectm, but no transform is performed. Note that drawing is affected by the current Processing transform.- Parameters:
parent- PApplet used for calls to the Processing environment, notably for drawingx- x-coordinate of initial pointy- y-coordinate of initial pointisClosed- true if shape is closed, false if it is open
-
-
Method Details
-
x
public float x()Returns the x-coordinate of the initial point of the geometry of this shape.- Returns:
- x-coordinate of initial vertex
-
setX
public void setX(float newX) Sets the x-coordinate of the initial point of the geometry of this shape.- Parameters:
newX- new x-coordinate of initial vertex
-
y
public float y()Returns the y-coordinate of the initial point of the geometry of this shape.- Returns:
- y-coordinate of initial vertex
-
setY
public void setY(float newY) Sets the y-coordinate of the initial point of the geometry of this shape.- Parameters:
newY- new y-coordinate of initial vertex
-
startVertex
- Returns:
- a PauLineVertex with start point coordinates of this shape
-
setStartPoint
public void setStartPoint(float newX, float newY) Sets a new initial vertex for this BezShape.- Parameters:
newX-newY-
-
isClosed
public boolean isClosed()- Returns:
trueif this shape is closed,falseotherwise.
-
setIsClosed
public void setIsClosed(boolean newIsClosed) - Parameters:
newIsClosed-trueif this shape is closed,falseotherwise
-
isMarked
public boolean isMarked()- Returns:
trueif this shape is marked with vertices and control points,falseotherwise.
-
setIsMarked
public void setIsMarked(boolean newIsMarked) - Parameters:
newIsMarked-trueif this shape is marked with vertices and control points,falseotherwise
-
hasFill
public boolean hasFill()- Returns:
- true if this component is filled, false otherwise
-
setHasFill
public void setHasFill(boolean newHasFill) - Parameters:
newHasFill- pass true if this shape has a fill, false otherwise. Note that the current fillColor will not be discarded by setting hasFill to false: the shape simply won't display or save to file with a fill.
-
setNoFill
public void setNoFill()Marks this component as having no fill. Equivalent to setHasFill(false), if the implementor provides a setHasFill method -
hasStroke
public boolean hasStroke()- Returns:
- true if this shape is stroked, false otherwise
-
setHasStroke
public void setHasStroke(boolean newHasStroke) - Parameters:
newHasStroke- pass true if this shape has a stroke, false otherwise. Note that the current strokeColor will not be discarded by setting hasStroke to false: the shape simply won't display or save to file with a stroke.
-
setNoStroke
public void setNoStroke()Marks this component as having no stroke Equivalent to setHasStroke(false), if the implementor provides a setHasStroke method -
fillColor
public int fillColor()- Returns:
- the current fill color
-
setFillColor
public void setFillColor(int newFillColor) - Parameters:
newFillColor- a Processing color (32-bit int with ARGB bytes).
-
strokeColor
public int strokeColor()- Returns:
- the current stroke color
-
setStrokeColor
public void setStrokeColor(int newStrokeColor) - Parameters:
newStrokeColor- a Processing color (32-bit int with ARGB bytes).
-
setFillOpacity
public void setFillOpacity(int opacity) Sets opacity of current fill color.- Parameters:
opacity- a number in the range 0..255. Value is not checked!
-
fillOpacity
public int fillOpacity()- Returns:
- the opacity value of the current fill color
-
setStrokeOpacity
public void setStrokeOpacity(int opacity) Sets opacity of current stroke color.- Parameters:
opacity- a number in the range 0..255. Value is not checked!
-
strokeOpacity
public int strokeOpacity()- Returns:
- the opacity value of the current stroke color
-
weight
public float weight()Returns the current weight (in points) of stroked lines.- Returns:
- the current weight (in points) of stroked lines. One point = one pixel on screen.
-
setWeight
public void setWeight(float newWeight) - Parameters:
newWeight- the new weight of stroked lines.
-
rgbComponents
public static int[] rgbComponents(int rgb) Breaks a Processing color into R, G and B values in an array.- Parameters:
rgb- a Processing color as a 32-bit integer- Returns:
- an array of 3 integers in the intRange 0..255 for 3 primary color components: {R, G, B}
-
argbComponents
public static int[] argbComponents(int argb) Breaks a Processing color into A, R, G and B values in an array.- Parameters:
argb- a Processing color as a 32-bit integer- Returns:
- an array of 4 integers in the range 0..255 for each color component: {A, R, G, B}
-
rgbaComponents
public static int[] rgbaComponents(int argb) Breaks a Processing color into R, G, B and A values in an array.- Parameters:
argb- a Processing color as a 32-bit integer- Returns:
- an array of integers in the intRange [0, 255] for 3 primary color components: {R, G, B} plus alpha
-
composeColor
public static int composeColor(int r, int g, int b) Creates an opaque Processing RGB color from r, g, b values. Note the order of arguments, the same as the Processing color(value1, value2, value3) method.- Parameters:
r- red component [0, 255]g- green component [0, 255]b- blue component [0, 255]- Returns:
- a 32-bit integer with bytes in Processing format ARGB.
-
composeColor
public static final int composeColor(int r, int g, int b, int a) Creates a Processing ARGB color from r, g, b, and alpha channel values. Note the order of arguments, the same as the Processing color(value1, value2, value3, alpha) method.- Parameters:
r- red component [0, 255]g- green component [0, 255]b- blue component [0, 255]a- alpha component [0, 255]- Returns:
- a 32-bit integer with bytes in Processing format ARGB.
-
composeColor
public static int composeColor(int[] comp) Creates a Processing ARGB color from r, g, b, values in an array.- Parameters:
comp- array of 3 integers in range [0, 255], for red, green and blue components of color alpha value is assumed to be 255- Returns:
- a 32-bit integer with bytes in Processing format ARGB.
-
composeColor
public static int composeColor(int gray) Creates a Processing ARGB color from a grayscale value. Alpha is set to 255.- Parameters:
gray- a grayscale value 0..255- Returns:
- an int compatible with a Processing color
-
append
Appends a Vertex2DINF to this BezShape- Parameters:
vt- a PauVertex2DINF (line segment or curve segment)
-
append
public void append(float cx1, float cy1, float cx2, float cy2, float x, float y) Appends a PauBezVertex (cubic Bezier segment) to this BezShape.- Parameters:
cx1- x-coordinate of first control pointcy1- y-coordinate of first control pointcx2- x-coordinate of second control pointcy2- y-coordinate of second control pointx- x-coordinate of terminal anchor pointy- y-coordinate of terminal anchor point
-
append
public void append(float x, float y) Appends a LineVertex (line segment) to this BezShape.- Parameters:
x-y-
-
curveIterator
Returns an iterator over the geometry of this shape. Preferred method for accessing geometry. Does not include the initial point, call x() and y() or startVertex() for that.- Returns:
- an iterator over the PauVertex2DINF segments that comprise the geometry of this shape
-
size
public int size()Returns size of number of vertices (PauBezVertex and LineVertex) in curves.- Returns:
- size of curves ArrayList.
-
pointCount
public int pointCount()Returns number of points (anchor points and control points) in curves. Dosn't count the start point.- Returns:
- total numbr of points in curves ArrayList data.
-
clone
Creates a deep copy of this BezShape. -
drawQuick
public void drawQuick(processing.core.PApplet parent) Draws this shape to the display. Calls beginShape and endShape on its own. Uses current fill, stroke and weight from Processing environment. -
drawQuick
public void drawQuick(processing.core.PGraphics pg) Draws this shape to a PGraphics passed as an argument. Calls beginShape and endShape on its own. Uses current fill, stroke and weight from Processing environment. -
draw
public void draw(processing.core.PApplet parent) Draws this shape to the display. Calls beginShape and endShape on its own. If isMarked is true, will mark anchor and control points. -
draw
public void draw(processing.core.PGraphics pg) Draws this shape to an offscreen PGraphics. Calls beginShape and endShape on its own. It's up to the user to call beginDraw() and endDraw() on the PGraphics instance. If isMarked is true, draws marks for anchor and control points.- Parameters:
pg- a PGraphics instance
-
getPointList
@Deprecated public ArrayList<processing.core.PVector> getPointList(processing.core.PApplet parent, int steps) Deprecated.Extracts an approximated polygon from path data, returning it as an array of PVector. We no longer require a PApplet instance to calculate the bezierPoint.- Parameters:
parent- a PApplet instancesteps- number of straight line segments to divide Bezier curves into- Returns:
- ArrayList of PVector, coordinates for a polygon approximation of this shape.
-
getPointList
Extracts an approximated polygon from path data, returning it as an array of PVector.- Parameters:
steps- number of straight line segments to divide Bezier curves into- Returns:
- ArrayList of PVector, coordinates for a polygon approximation of this shape.
-
getPointList
@Deprecated public ArrayList<processing.core.PVector> getPointList(processing.core.PGraphics pg, int steps) Deprecated.Extracts an approximated polygon from path data, returning it as an array of PVector. We no longer require a PGraphics instance to calculate the bezierPoint.- Parameters:
pg- a PGraphics instancesteps- number of straight line segments to divide Bezier curves- Returns:
- ArrayList of PVector, coordinates for a polygon approximation of this shape.
-
bezierPoint
public float bezierPoint(float a, float b, float c, float d, float t) Evaluates the Bezier at point t for points a, b, c, d. The parameter t varies between 0 and 1, a and d are points on the curve, and b and c are the control points. This can be done once with the x coordinates and a second time with the y coordinates to get the location of a Bézier curve at t. Evaluation takes multiple calls, once each for x and y coordinates, in two dimensions.
- Parameters:
a- coordinate of first point on the curveb- coordinate of first control pointc- coordinate of second control pointd- coordinate of second point on the curvet- value between 0 and 1- Returns:
- single coordinate value of a point on the curve
- See Also:
-
bezierTangent
public float bezierTangent(float a, float b, float c, float d, float t) Calculates the tangent of a point on a Bézier curve. There is a good definition of tangent on Wikipedia. Evaluation takes multiple calls, once each for x and y coordinates, in two dimensions.
From Processing GitHub repo:
Code submitted by Dave Bollinger (davbol) for release 0136.
- Parameters:
a- coordinate of first point on the curveb- coordinate of first control pointc- coordinate of second control pointd- coordinate of second point on the curvet- value between 0 and 1- Returns:
- a single coordinate value of endpoint of the tangent
- See Also:
-
bounds
protected float[] bounds()Calculates the boundary rectangle of this shape and returns it as an array of floats.- Returns:
- [xMin, yMin, xMax, yMax]
-
getBounds
public float[] getBounds()- Returns:
- bounding rectangle of this shape as an array of floats, [xMin, yMin, xMax, yMax]
-
setBounds
public void setBounds(float[] newBounds) -
getBoundsCenter
public processing.core.PVector getBoundsCenter() -
translateShape
public void translateShape(float xTrans, float yTrans) Translates this shape in x and y directions.- Parameters:
xTrans-yTrans-
-
scaleShape
public void scaleShape(float xScale, float yScale, float x0, float y0) Scales this shape around a given point. Sets xcoords and ycoords arrays to null: they will have to be recalculated after a transform, which will be done through lazy initialization whenxcoords()orycoords()are called.- Parameters:
xScale- scaling on x-axisyScale- scaling on y-axis
-
rotateShape
public void rotateShape(float xctr, float yctr, float theta) Rotates this shape around a supplied center point.- Parameters:
theta- degrees to rotate (in radians) TODO for theta very near PI, 0, or TWO_PI, insure correct rotation.
-
translateCoord
public static processing.core.PVector translateCoord(float x, float y, float xOffset, float yOffset) Translates a point by xOffset and yOffset, returns a new point.- Parameters:
x- x coordinate of pointy- y coordinate of pointxOffset- distance to translate on x-xisyOffset- distance to translate on y-axis- Returns:
- a new translated point
-
scaleCoordAroundPoint
public static processing.core.PVector scaleCoordAroundPoint(float x, float y, float xScale, float yScale, float xctr, float yctr) Scales a point by xScale and yScale around a point (xctr, yctr), returns a new point.- Parameters:
x- x coordinate of pointy- y coordinate of pointxScale- scaling on x-axisyScale- scaling on y-axisxctr- x coordinate of center of transformationyctr- y coordinate of center of transformation- Returns:
- a new scaled point as a PVector
-
rotateCoordAroundPoint
public static processing.core.PVector rotateCoordAroundPoint(float x, float y, float xctr, float yctr, float theta) Rotates a point theta radians around a point (xctr, yctr), returns a new point. rotation is counterclockwise for positive theta in Cartesian system, clockwise in screen display coordinate system- Parameters:
x- x coordinate of pointy- y coordinate of pointxctr- x coordinate of center of rotationyctr- y coordinate of center of rotationtheta- angle to rotate, in radians- Returns:
- a new rotated point
-
pointInPoly
Decides if a point is inside a polygon, returns true if it is.- Parameters:
npol- number of points in polygonpoly- an array of PVectors representing a polygonx- x-coordinate of pointy- y-coordinate of point- Returns:
- true if point is in polygon, false otherwise
-