Class PACurveMaker
- All Implemented Interfaces:
PAGesture
PACurveMaker is a utility and storage class for gestures and curve modeling, with
point reduction and drawing to on-screen PApplets or off-screen PGraphics. It implements
PAGesture and provides a pair of data structures, dragPoints and dragTimes,
that together capture gestures made with a mouse or similar input device.
Each point in dragPoints is associated with a corresponding time in dragTimes.
You can use PACurveMaker for data storage in interactive drawing applications, or
implement your own storage with just the features you require. It is a key
data structure for playing digital audio instruments using granular synthesis and sampling
in the net.paulhertz.pixelaudio.granular and net.paulhertz.pixelaudio.sampler packages.
PACUrveMaker makes extensive use of PACurveUtility's static methods and provides a wide range of graphic objects and properties for dense point arrays, reduced point arrays, derived Bezier curves (weighted and not weighted), brushstroke Bezier shapes for drawing to the display, and brushstroke polygons for point testing with PABezShape.pointInPoly(). It provides some basic timing data associated with drawing to the screen. You can use PACurveUtility for drawing all PACurveMaker data formats or you can use the built-in commands if you use PACurveMaker as a storage class.
PACurveMaker's factory methods take as their principal argument a list of PVectors, dragPoints,
a list of time offsets in milliseconds, dragTimes, and an absolute time in milliseconds, startTimeMs.
The list of points is typically derived from a line drawn by dragging the mouse across the application
window. This line is stored in dragPoints and can be accessed with getDragPoints() or getAllPoints().
dragPoints can be mutated with mutateAllPoints, preserving its cardinality.
The dense point set in dragPoints can be processed by the Ramer-Douglas-Peucker algorithm to derive a
a reduced point set, rdpPoints. The algorithm is implemented in PACUrveUtilities. The reduced points
can be turned into a Bezier path, curveShape, where each point in rdpPoints becomes an anchor point
in curveShape. Bezier paths are modeled using PixelAudio's PABezShape class, which includes methods
for drawing attributes, affine transforms, and point testing. For display and interaction, a brushstroke
shape, brushShape, can be created from the curve. An array of PVectors,
eventPoints, can be created from curveShape to facilitate timed event-staging along the curve.
Another array of Pvectors, brushPoly, can be used to test points with PABezShape.pointInPoly().
---- TODO continue to revise documentation ----
Each of the geometric data objects--dragPoints, rdpPoints, curveShape, and brushShape--has method for drawing to the screen in a PApplet or drawing offscreen in a PGraphic. DragPoints and rdpPoints keep their drawing parameters (fill, stroke, weight) in PACurveMaker variables. PABezShapes like curveShape and brushShape can store drawing parameters internally.
There a several properties of PACurveMaker that can affect the appearance of curves. The value of epsilon
determines how closely the reduced point set in rdpPoints matches the dense point set in dragPoints.
Smaller values, down to 1.0, yield a reduced point set with more points and great precision. Some of the factory methods
allow you to supply your own value for epsilon, which defaults to 8.0. Weighted curves and brushstrokes are variations
on the smooth Bezier curves that PACurveMaker generates by default. In the default curves, the rate of change in
curvature is the same on either side of a Bezier anchor point. The weighted curves use a value, bezierBias, to
change the adjust the control points. The default bias value, PABezShape.LAMBDA, may provide a closer approximation
to rdpPoints. Other values can create extreme curves. It's worth some experimentation. If you call setDrawWeighted(true)
and then call calculateDerivedPoints(), curveShape and brushShape will be generated as weighted Bezier curves.
There are several calls to generate weighted Bezier curves. They do not set local variables, but can be useful
for exploring the variations created by different values of bezierBias. PACurveUtility can also create
weighted curves.
eventPoints is a List derived from the gestural points captured during user interaction.
dragPoints is reduced to rdpPoints. rdpPoints is used to derive the
Bezier path (PABezShape) curveShape. The polyline representation of curveShape is eventPoints,
where display events tied to the curve can be located.
To reduce confusion, I have created some alias methods in PACurveMaker:
// Alias method for getDragPoints().
public ArrayList getAllPoints() {
return this.getDragPoints();
}
// Alias for getRdpPoints().
public ArrayList getReducedPoints() {
return getRdpPoints();
}
// Sets epsilon and returns the reduced point set, this.rdpPoints
public ArrayList getReducedPoints(float epsilon) {
if (this.epsilon != epsilon || rdpPoints.size() < 1) {
this.setEpsilon(epsilon);
calculateDerivedPoints();
}
return rdpPoints;
}
// Alias for getCurveShape().
public PABezShape getCurve() {
return this.getCurveShape();
}
// Alias for getEventPoints().
public ArrayList getCurvePoints() {
return this.getEventPoints();
}
// Alias for getEventPoints(int eventSteps).
public ArrayList getCurvePoints(int curveSteps) {
return this.getEventPoints(curveSteps);
}
// Alias for eventSteps
public int getCurveSteps() {
return this.eventSteps;
}
In addition, I note that the primary point sets in PACUrveMaker are dragPoints (getAllPoints()),
rdpPoints (getCurvePoints()), and eventPoints (getCurvePoints()). The full
gesture is conveyed by dragPoints and dragTimes. The indices of rdpPoints are tracked
and stored in ArrayList rdpIndices , so that we can map back to the original gesture points
if needed. The points in rdpPoints are also the anchor points in the Bezier path curveShape,
produced from curveShape = PACurveUtility.calculateCurve(rdpPoints);.
We can also get the reduced time list:
public int[] getReducedTimes() {
int[] timeIndices = getRdpIndicesAsInts();
int[] rdpTimes = new int[timeIndices.length];
// the first value in dragTimes is a time stamp, all following numbers are offsets
// one for each point in dragPoints. We only need the offsets.
int[] allTimes = this.getDragOffsetsAsInts();
for (int i = 0; i < timeIndices.length; i++) {
rdpTimes[i] = allTimes[timeIndices[i]];
}
return rdpTimes;
}
Changing epsilon will change the reduced point set, and thus the Bezier curve and event points. rdpIndices must
be recalculated whenever epsilon is changed. This is done in PACurveMaker.calculateDerivedPoints(), which
is called from setEpsilon() and public ArrayList getReducedPoints(float epsilon) The new reduced
point time set can be derived from rdpIndices when needed.
NOTES 2025.12.23
As much as possible, PACurveMaker now relies on lazy initialization, though end user can initialize all geometry up from with
calculateDerivedPoints(). I have also introduced the interface PAGesture, to clarify how PACurveMaker structures originate
in capture gestures from a GUI or other source. A gesture is constructed from
1) a list of points and
2) a list of time offsets where
3) both lists have the same cardinality and
4) time offsets increase monotonically. In addition,
5) the time list is expected (but not required) to start with a first element 0.
Absolute time of gesture creation can be stored in startTime, as millis from application start.
I have also refactored the structure of dragTimes. It no longer has an absolute time stamp as its first element,
thus adhering the the cardinality rule stated above.
GestureSchedule provides some static methods to help enforce the invariants of gestures.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceSimple Processing-friendly callback interface. -
Field Summary
FieldsModifier and TypeFieldDescriptionintColor for highlighted brush stroke, stored in brushShapeprivate floatA weight applied to calculations of the control points for Bezier curvesintColor for simulated brushstroke fill and stroke, stored in brushShapebooleanusing a custom brush shapeprivate ArrayList<processing.core.PVector>polygon representation of brushShape, for point testing, etc.private PABezShapeA simulated brush stroke derived from curveShape, a closed shape rather than a curved linefloatThe distance in pixels between the edges of the brush stroke, double the distance from the central linefloatweight of stroke for brushStroke, set to 0 for no strokeintColor for Bezier curve derived from drawPoints, stored in bezPoints or weightedBezPointsprivate PABezShapeA path composed of Bezier curves and lines, a continuous curved line derived from rdpPointsfloatweight of curved line curveShapeprivate booleanprivate booleanprivate booleanprivate booleanprivate booleanintboolean value that determines whether curve and brush shapes are weightedprivate ArrayList<processing.core.PVector>List of non-repeating points that need to be reduced, typically from a UI gesture such as dragging a mouse, optical flow of a video image, flocks of boids, etc.private int[]List of time data: first element is expected to be 0 and the remaining elements are non-decreasing offsets in millis from the first element.(package private) float[]Cache for float[] version of dragTimesfloatweight of lines drawn between PVectors in allPointsprivate floatA parameter to control the amount of reduction in the RDP algorithmprivate ArrayList<processing.core.PVector>List of points where events such as audio samples can be triggered, derived from the polygon representation of curveShape, accessed with getEventPoints() or getCurvePoints()intcolor of eventPoints markersfloatsize of eventPoints markersintnumber of steps along a polygonized curve, used to produce eventPoints from curveShapebooleanboolean to determine if bezierBias, "weight", is applied to curve calculationsintnumber of steps along a polygonized brushstroke shape, used to produce brushPolyintColor for points reduced by RDP algorithm, stored in drawPointslist of indices of points in dragPoints captured for rdpPointsprivate ArrayList<processing.core.PVector>The reduced points returned by the RDP algorithmfloatweight of lines drawn between PVectors in drawPointsintTime of mouseReleased event, in milliseconds elapsed since timeStampintTime when CurveMaker instance was initialized by mousePressed event, in milliseconds since application startup -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivatePACurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs) Constructor for PACurveMaker, called by all factory methods. -
Method Summary
Modifier and TypeMethodDescriptionvoidbrushDraw(processing.core.PApplet parent) Draws the stored brushShape to a PApplet using local properties this.brushColor, this.brushColor, this.brushWeight.voidbrushDraw(processing.core.PApplet parent, int brushColor, int strokeColor, float brushWeight) Draws the stored brushShape to a PApplet using supplied fill color, stroke color, and weight.voidbrushDraw(processing.core.PGraphics pg) Draws the stored brushShape to an offscreen PGraphics using local properties this.brushColor, this.brushColor, this.brushWeight.voidbrushDraw(processing.core.PGraphics pg, int brushColor, int strokeColor, float brushWeight) Draws the stored brushShape to an offscreen PGraphics using supplied fill color, stroke color, and weight.voidbrushDrawDirect(processing.core.PApplet parent) Draws the stored brush shape to a PApplet using its properties as a PABezShape.voidbrushDrawDirect(processing.core.PGraphics pg) Draws the stored brush shape to an offscreen PGraphics using its properties as a PABezShape.buildBrushShape(ArrayList<processing.core.PVector> knotPoints) static PACurveMakerbuildCurveMaker(ArrayList<processing.core.PVector> dragPoints) This factory method can be used when you are only using the curve modeling features of PACurveMaker.static PACurveMakerbuildCurveMaker(ArrayList<processing.core.PVector> dragPoints, float epsilon) This factory method can be used when you are only using the curve modeling features of PACurveMaker.static PACurveMakerbuildCurveMaker(ArrayList<processing.core.PVector> points, float epsilon, float brushSize, int brushColor) This factory method can be used when you are only using the curve modeling features of PACurveMaker.static PACurveMakerbuildCurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs) static PACurveMakerbuildCurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs, float epsilon) static PACurveMakerbuildCurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs, float epsilon, float brushSize, int brushColor) static PACurveMakerbuildCurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs, float epsilon, int dragColor, float dragWeight, int rdpColor, float rdpWeight, int curveColor, float curveWeight, int brushColor, float brushWeight, int activeBrushColor) Creates a PACurveMaker instance set up for lazy initialization.voidWe can build all the relevant data structures for geometry here, typically on initialization.voidSets brushIsCustom to false, prepares rebuild of brush from curveShapeArrayList<processing.core.PVector>voidcurveDraw(processing.core.PApplet parent) Draws a Bezier curve using the 2D Bezier curve data in this.curveShape and the current values of this.curveColor and this.curveWeight.voidcurveDraw(processing.core.PGraphics pg) Draws a Bezier curve using the 2D Bezier curve data in this.curveShape and the current values of this.curveColor and this.curveWeight.voidcurveDrawDirect(processing.core.PApplet parent) Draws a Bezier curve using local drawing properties of curveShape.voidcurveDrawDirect(processing.core.PGraphics pg) Draws a Bezier curve using local drawing properties of this.curveShape as a PABezShape.voiddragPointsDraw(processing.core.PApplet parent) Draws a line using the PVector data in allPoints and the current values of this.dragColor and this.dragWeight.voiddragPointsDraw(processing.core.PApplet parent, int lineColor, float lineWeight) Draws a line using the PVector data in dragPoints and a supplied color.voiddragPointsDraw(processing.core.PGraphics pg) Draws dragPoints to a PGraphics using local color and weight, this.dragColor and this.dragWeight.voiddragPointsDraw(processing.core.PGraphics pg, int lineColor, float lineWeight) Draws dragPoints to a PGraphics using supplied color and weight.private voidprivate voidprivate voidprivate voidprivate voidvoideventPointsDraw(processing.core.PApplet parent) Draws this.eventPoints to a PApplet as circles using local properties this.eventPointsColor and this.eventPointsSize.voideventPointsDraw(processing.core.PApplet parent, int eventPointsColor, float eventPointsSize) Draws this.eventPoints to a PApplet as circles using supplied properties eventPointsColor and eventPointsSize.voideventPointsDraw(processing.core.PApplet parent, int eventSteps, int eventPointsColor, float eventPointsSize) Draws this.eventPoints to a PApplet as circles using supplied properties eventPointsSteps, eventPointsColor and eventPointsSize.voideventPointsDraw(processing.core.PGraphics pg) Draws this.eventPoints to an offscreen PGraphics as circles using local properties this.eventPointsColor and this.eventPointsSize.voideventPointsDraw(processing.core.PGraphics pg, int eventPointsColor, float eventPointsSize) Draws this.eventPoints to an offscreen PGraphics as circles using supplied properties eventPointsColor and eventPointsSize.voideventPointsDraw(processing.core.PGraphics pg, int eventSteps, int eventPointsColor, float eventPointsSize) Draws this.eventPoints to an offscreen PGraphics as circles using supplied properties eventPointsSteps, eventPointsColor and eventPointsSize.intArrayList<processing.core.PVector>Alias method for getDragPoints().Convenience: a schedule over the dense gesture.int[]getAllTimes() is a convenient alias for getDragTimes()floatintArrayList<processing.core.PVector>floatfloatgetCurve()Alias for getCurveShape().intArrayList<processing.core.PVector>Alias for getEventPoints().ArrayList<processing.core.PVector>getCurvePoints(int curveSteps) Alias for getEventPoints(int curveSteps).getCurveSchedule(float epsilon, int curveSteps, boolean arcLengthTime) intfloatintArrayList<processing.core.PVector>int[]floatfloatArrayList<processing.core.PVector>ArrayList<processing.core.PVector>getEventPoints(int eventSteps) intfloatintintintint[]ArrayList<processing.core.PVector>floatArrayList<processing.core.PVector>Alias for getReducedPoints(this.epsilon).ArrayList<processing.core.PVector>getReducedPoints(float epsilon) Sets epsilon and returns the reduced point set, this.rdpPointsgetReducedSchedule(float epsilon) int[]longAbsolute start time (e.g.intfloat[]Returns time offsets as floats.intgetWeightedBrushShape(float brushSize, float bias) getWeightedCurveShape(float bias) Calculates a PABezSHape with distances between control points and anchor points adjusted by bezierBias.booleanbooleanisReady()voidCall after mutating dragPoints contents or order (or changing dragTimes length).voidCall after changing brush size/weighting/bias.voidCall after changing only curveSteps/eventSteps.voidCall after changing only epsilon-sensitive state (typically point geometry changed).voidMutate the live dragPoints list (and/or its PVectors) and automatically mark cached geometry as dirty afterward.private static int[]normalizeOffsets(int[] t) voidreducedPointsDraw(processing.core.PApplet parent) Draws a line using the PVector data in rdpPoints and the current values of this.rdpColor and this.rdpWeight.voidreducedPointsDraw(processing.core.PApplet parent, int lineColor, float lineWeight) Draws a line using the PVector data in drawPoints, the reduced point set derived from allPoints.voidreducedPointsDraw(processing.core.PGraphics pg) Draws drawPoints to a PGraphics using current values of this.rdpColor and this.rdpWeight.voidreducedPointsDraw(processing.core.PGraphics pg, int lineColor, float lineWeight) Draws rdpPoints to a PGraphics using supplied color and weight.private voidreducePoints(float epsilon) Takes the list of points in allPoints and generates a reduced list in drawPoints.voidsetActiveBrushColor(int activeBrushColor) voidsetBezierBias(float bias) voidsetBrushColor(int brushColor) voidsetBrushSize(float newSize) Set the distance in pixels between opposite edges of a brushstroke.voidsetBrushWeight(float brushWeight) voidsetCurveColor(int curveColor) voidsetCurveSteps(int curveSteps) voidsetCurveWeight(float curveWeight) voidsetCustomBrushShape(PABezShape customBrushShape) Replaces the closed PABezShape "brushstroke" with a shape of your own choosing.voidsetDragColor(int dragColor) voidsetDragPoints(ArrayList<processing.core.PVector> dragPoints) Deprecated.voidsetDragTimes(int[] dragTimes) voidsetDragTimes(List<Integer> dragTimes) voidsetDragWeight(float dragWeight) voidsetDrawingProperties(int dragColor, float dragWeight, int rdpColor, float rdpWeight, int curveColor, float curveWeight, int brushColor, float brushWeight, int activeBrushColor) Sets various properties used for drawing PACurveMaker graphics.voidsetDrawWeighted(boolean drawBiased) Flag whether to draw weighted Bezier curves, displacing control points from the anchor by a specified bias, bezierBias.voidsetEpsilon(float eps) Sets value of variable epsilon, used in reduced point set calculations.voidsetEventPointsColor(int eventPointsColor) voidsetEventPointsSize(float eventPointsSize) voidsetEventSteps(int steps) If eventPoints is null or if eventSteps differs from the old value, sets a new value for eventSteps and calculates eventPoints.voidsetPolySteps(int steps) voidsetRdpColor(int rdpColor) voidsetRdpIndices(ArrayList<Integer> rdpIndices) Deprecated.voidsetRdpPoints(ArrayList<processing.core.PVector> rdpPoints) Deprecated.voidsetRdpWeight(float rdpWeight) voidsetTimeOffset(int timeOffset) voidsetTimeStamp(int timeStamp)
-
Field Details
-
dragPoints
List of non-repeating points that need to be reduced, typically from a UI gesture such as dragging a mouse, optical flow of a video image, flocks of boids, etc. -
rdpPoints
The reduced points returned by the RDP algorithm -
rdpIndices
list of indices of points in dragPoints captured for rdpPoints -
epsilon
private float epsilonA parameter to control the amount of reduction in the RDP algorithm -
curveShape
A path composed of Bezier curves and lines, a continuous curved line derived from rdpPoints -
eventPoints
List of points where events such as audio samples can be triggered, derived from the polygon representation of curveShape, accessed with getEventPoints() or getCurvePoints() -
eventSteps
public int eventStepsnumber of steps along a polygonized curve, used to produce eventPoints from curveShape -
brushShape
A simulated brush stroke derived from curveShape, a closed shape rather than a curved line -
brushPoly
polygon representation of brushShape, for point testing, etc. -
polySteps
public int polyStepsnumber of steps along a polygonized brushstroke shape, used to produce brushPoly -
timeStamp
public int timeStampTime when CurveMaker instance was initialized by mousePressed event, in milliseconds since application startup -
timeOffset
public int timeOffsetTime of mouseReleased event, in milliseconds elapsed since timeStamp -
dragTimes
private int[] dragTimesList of time data: first element is expected to be 0 and the remaining elements are non-decreasing offsets in millis from the first element. -
dragTimesFloat
float[] dragTimesFloatCache for float[] version of dragTimes -
isDrawWeighted
public boolean isDrawWeightedboolean to determine if bezierBias, "weight", is applied to curve calculations -
bezierBias
private float bezierBiasA weight applied to calculations of the control points for Bezier curves -
brushSize
public float brushSizeThe distance in pixels between the edges of the brush stroke, double the distance from the central line -
dragColor
public int dragColorboolean value that determines whether curve and brush shapes are weighted -
dragWeight
public float dragWeightweight of lines drawn between PVectors in allPoints -
rdpColor
public int rdpColorColor for points reduced by RDP algorithm, stored in drawPoints -
rdpWeight
public float rdpWeightweight of lines drawn between PVectors in drawPoints -
curveColor
public int curveColorColor for Bezier curve derived from drawPoints, stored in bezPoints or weightedBezPoints -
curveWeight
public float curveWeightweight of curved line curveShape -
brushColor
public int brushColorColor for simulated brushstroke fill and stroke, stored in brushShape -
activeBrushColor
public int activeBrushColorColor for highlighted brush stroke, stored in brushShape -
brushWeight
public float brushWeightweight of stroke for brushStroke, set to 0 for no stroke -
eventPointsColor
public int eventPointsColorcolor of eventPoints markers -
eventPointsSize
public float eventPointsSizesize of eventPoints markers -
brushIsCustom
public boolean brushIsCustomusing a custom brush shape -
dirtyReduced
private boolean dirtyReduced -
dirtyCurve
private boolean dirtyCurve -
dirtyEvent
private boolean dirtyEvent -
dirtyBrush
private boolean dirtyBrush -
dirtyBrushPoly
private boolean dirtyBrushPoly
-
-
Constructor Details
-
PACurveMaker
private PACurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs) Constructor for PACurveMaker, called by all factory methods.- Parameters:
dragPoints- a list of points (PVector) where no two successive points are identicaldragTimes- a list of times in milliseconds, successively offset from first entry of 0startTimeMs- an absolute time in milliseconds, determined by the application, for the gesture to begin
-
-
Method Details
-
buildCurveMaker
public static PACurveMaker buildCurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs) - Parameters:
dragPoints- a list of points (PVector) where no two successive points are identicaldragTimes- a list of times in milliseconds, successively offset from first entry of 0startTimeMs- an absolute time in milliseconds, determined by the application, for the gesture to begin- Returns:
- a PACurveMaker instance, set up for lazy initialization
-
buildCurveMaker
public static PACurveMaker buildCurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs, float epsilon) - Parameters:
dragPoints- a list of points (PVector) where no two successive points are identicaldragTimes- a list of times in milliseconds, successively offset from first entry of 0startTimeMs- an absolute time in milliseconds, determined by the application, for the gesture to beginepsilon- the expected distance between reduced points, lower values typically produce more points- Returns:
- a PACurveMaker instance, set up for lazy initialization
-
buildCurveMaker
public static PACurveMaker buildCurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs, float epsilon, float brushSize, int brushColor) - Parameters:
dragPoints- a list of points (PVector) where no two successive points are identicaldragTimes- a list of times in milliseconds, successively offset from first entry of 0startTimeMs- an absolute time in milliseconds, determined by the application, for the gesture to beginepsilon- the expected distance between reduced points, lower values typically produce more pointsbrushSize- the width in pixels of a simulated brushstroke created from the Bezier path derived from rdpPointsbrushColor- the color assigned to the brushstroke- Returns:
- a PACurveMaker instance, set up for lazy initialization
-
buildCurveMaker
This factory method can be used when you are only using the curve modeling features of PACurveMaker. Entries in the time offsets list dragTimes will be set to 0 and startTimesMs will be set to 0. If you set values for dragTimes and startTimeMs later, dragTimes and dragPoints must be the same size.- Parameters:
dragPoints- a list of points (PVector) where no two successive points are identical- Returns:
- a PACUrveMaker instance
-
buildCurveMaker
public static PACurveMaker buildCurveMaker(ArrayList<processing.core.PVector> dragPoints, float epsilon) This factory method can be used when you are only using the curve modeling features of PACurveMaker. Entries in the time offsets list dragTimes will be set to 0 and startTimesMs will be set to 0. If you set values for dragTimes and startTimeMs later, dragTimes and dragPoints must be the same size.- Parameters:
dragPoints- a list of points (PVector), where no two successive points are identicalepsilon- controls amount of thinning of points to derive the reduced point set rdpPoints from dragPoints- Returns:
- a PACurveMaker instance
-
buildCurveMaker
public static PACurveMaker buildCurveMaker(ArrayList<processing.core.PVector> points, float epsilon, float brushSize, int brushColor) This factory method can be used when you are only using the curve modeling features of PACurveMaker. Entries in the time offsets list dragTimes will be set to 0 and startTimesMs will be set to 0. If you set values for dragTimes and startTimeMs later, dragTimes and dragPoints must be the same size.- Parameters:
dragPoints- a list of points (PVector), where no two successive points are identicalepsilon- controls amount of thinning of points to derive the reduced point set rdpPoints from dragPointsbrushSize- the width in pixels of a simulated brushstroke created from the Bezier path derived from rdpPointsbrushColor- the color assigned to the brushstroke- Returns:
- a PACurveMaker instance
-
buildCurveMaker
public static PACurveMaker buildCurveMaker(List<processing.core.PVector> dragPoints, List<Integer> dragTimes, int startTimeMs, float epsilon, int dragColor, float dragWeight, int rdpColor, float rdpWeight, int curveColor, float curveWeight, int brushColor, float brushWeight, int activeBrushColor) Creates a PACurveMaker instance set up for lazy initialization. Sets various properties used for drawing PACurveMaker graphics.- Parameters:
dragPoints-dragTimes-startTimeMs-epsilon-dragColor-dragWeight-rdpColor-rdpWeight-curveColor-curveWeight-brushColor-brushWeight-activeBrushColor-- Returns:
-
setDrawingProperties
public void setDrawingProperties(int dragColor, float dragWeight, int rdpColor, float rdpWeight, int curveColor, float curveWeight, int brushColor, float brushWeight, int activeBrushColor) Sets various properties used for drawing PACurveMaker graphics.- Parameters:
dragColor-dragWeight-rdpColor-rdpWeight-curveColor-curveWeight-brushColor-brushWeight-activeBrushColor-
-
normalizeOffsets
private static int[] normalizeOffsets(int[] t) -
reducePoints
private void reducePoints(float epsilon) Takes the list of points in allPoints and generates a reduced list in drawPoints.- Parameters:
epsilon- controls amount of thinning applied to dragPoints to derive rdpPoints
-
calculateDerivedPoints
public void calculateDerivedPoints()We can build all the relevant data structures for geometry here, typically on initialization. After that, we can rely on lazy rebuilding, using the "dirty flags". Calculates rdpPoints, curveShape, eventPoints, brushShape and brushPoly. Sets isReady to true on completion. Call calculateDerivedPoints to refresh the drawing objects rdpPoints, curveShape, eventPoints, brushShape, and brushPoly. -
isReady
public boolean isReady() -
getDragPoints
-
copyAllPoints
-
getAllPoints
Alias method for getDragPoints().- Specified by:
getAllPointsin interfacePAGesture- Returns:
- ArrayList of PVector
-
setDragPoints
Deprecated.TODO remove: use mutateAllPoints() to change points. Changes the value of dragPoints and immediately calls calculateDerivedPoints() to refresh all drawing objects.- Parameters:
dragPoints- ArrayList, a dense set of points for drawing a line
-
mutateAllPoints
Mutate the live dragPoints list (and/or its PVectors) and automatically mark cached geometry as dirty afterward. Typical use: translating/scaling/warping points for animation. IMPORTANT: - If you change the number/order of points, you must also update dragTimes so that (dragTimes.size() == dragPoints.size()). -
markDirtyAll
public void markDirtyAll()Call after mutating dragPoints contents or order (or changing dragTimes length). -
markDirtyReduced
public void markDirtyReduced()Call after changing only epsilon-sensitive state (typically point geometry changed). -
markDirtyEventPoints
public void markDirtyEventPoints()Call after changing only curveSteps/eventSteps. -
markDirtyBrush
public void markDirtyBrush()Call after changing brush size/weighting/bias. -
getEpsilon
public float getEpsilon() -
setEpsilon
public void setEpsilon(float eps) Sets value of variable epsilon, used in reduced point set calculations. If the new value is not equal to the old value, will trigger various "dirty flags" to force rebuild of cached values.- Parameters:
eps- value for epsilon
-
getRdpPoints
-
getReducedPoints
Alias for getReducedPoints(this.epsilon).- Returns:
- a list of PVectors, the reduced point set for this PACurveMaker.
-
getReducedPoints
Sets epsilon and returns the reduced point set, this.rdpPoints- Parameters:
epsilon- parameter for RDP algorithm, determines distance/angle for culling points- Returns:
-
ensureReduced
private void ensureReduced() -
setRdpPoints
Deprecated.Sets rdpPoints, generally not something you want to do: let reducePoints() or calculateDerivedPoints() derive rdpPoints from dragPoints instead.- Parameters:
rdpPoints-
-
getRdpIndices
-
getRdpIndicesAsInts
public int[] getRdpIndicesAsInts() -
setRdpIndices
Deprecated.Sets rdpIndices, generally not something you want to do. Call reducePoints() or calculateDerivedPoints instead and stay out of trouble.- Parameters:
rdpIndices-
-
getEventSteps
public int getEventSteps() -
getCurveSteps
public int getCurveSteps() -
setCurveSteps
public void setCurveSteps(int curveSteps) -
setEventSteps
public void setEventSteps(int steps) If eventPoints is null or if eventSteps differs from the old value, sets a new value for eventSteps and calculates eventPoints.- Parameters:
steps- a new value for eventSteps
-
getEventPoints
- Returns:
- this.eventPoints, the points along a polyline version of the Bezier curve derived from the reduced point set.
-
getEventPoints
- Parameters:
eventSteps- the number of points along each polyline curve in the PABezShape this.curveShape- Returns:
- this.eventPoints, the points along a polyline version of the Bezier curve derived from the reduced point set.
-
getCurvePoints
Alias for getEventPoints().- Returns:
- this.eventPoints, the points along a polyline version of the Bezier curve derived from the reduced point set.
-
getCurvePoints
Alias for getEventPoints(int curveSteps).- Parameters:
curveSteps-- Returns:
- points along a polyline version of the Bezier curve derived from the reduced point set.
-
ensureEventPoints
private void ensureEventPoints() -
getCurveShape
- Returns:
- PABezShape for the curved line derived from the reduced point set.
-
getCurve
Alias for getCurveShape().- Returns:
- PABezShape for the curved line derived from the reduced point set.
-
ensureCurve
private void ensureCurve() -
getWeightedCurveShape
Calculates a PABezSHape with distances between control points and anchor points adjusted by bezierBias. Does not store the returned curve.- Parameters:
bias- a parameter to adjust distances between Bezier anchor points and control points.- Returns:
- a Bezier curve shape whose control points are adjusted using bezierBias.
-
getWeightedCurveShape
-
isDrawWeighted
public boolean isDrawWeighted() -
setDrawWeighted
public void setDrawWeighted(boolean drawBiased) Flag whether to draw weighted Bezier curves, displacing control points from the anchor by a specified bias, bezierBias. For example, we use the bias value PABezShape.KAPPA, to draw circles with four equidistant anchor points.- Parameters:
drawBiased-
-
getBezierBias
public float getBezierBias() -
setBezierBias
public void setBezierBias(float bias) -
getBrushSize
public float getBrushSize() -
setBrushSize
public void setBrushSize(float newSize) Set the distance in pixels between opposite edges of a brushstroke.- Parameters:
newSize-
-
getBrushShape
- Returns:
- a PABezShape that looks like a brushstroke, created by expanding curveShape, an open Bezier path, into a closed Bezier path. Handy for interaction with gesture data.
-
ensureBrush
private void ensureBrush() -
getWeightedBrushShape
- Returns:
- a PABezShape modifed by the bezierBias value, equal to PABezShape.LAMBDA by default. Experiment to see how values above and below LAMBDA affect the curves.
-
getWeightedBrushShape
- Parameters:
brushSize-bias-- Returns:
- a PABezShape modifed by the bezierBias value, equal to PABezShape.LAMBDA by default. Experiment to see how values above and below LAMBDA affect the curves.
-
buildBrushShape
- Parameters:
knotPoints- a list of points that will be used to derive anchor points- Returns:
- a closed Bezier path shaped like a stylized brushstroke around the supplied knotPoints
-
setCustomBrushShape
Replaces the closed PABezShape "brushstroke" with a shape of your own choosing. Useful to provide a point of interaction. Rely on dragPoints or curveShape and dragTimes for gestures and timing.- Parameters:
customBrushShape-
-
clearCustomBrushShape
public void clearCustomBrushShape()Sets brushIsCustom to false, prepares rebuild of brush from curveShape -
getBrushPoly
- Returns:
- a list of points that comprise a closed polygonal shape that closely folllows the brushstroke. Useful for point in polygon testing for interaction. If you replaced the brush with your own PABezShape, you'll get a polygonal representation of your own shape.
-
ensureBrushPoly
private void ensureBrushPoly() -
getPolySteps
public int getPolySteps()- Returns:
- the number of divisions of each Bezier curve in the polygonal representation of brushShape.
-
setPolySteps
public void setPolySteps(int steps) - Parameters:
steps- the number of divisions of each Bezier curve in the polygonal representation of brushShape. See also setEventSteps().
-
getTimeStamp
public int getTimeStamp() -
setTimeStamp
public void setTimeStamp(int timeStamp) -
getStartTimeMs
public long getStartTimeMs()Description copied from interface:PAGestureAbsolute start time (e.g. millis() when gesture began)- Specified by:
getStartTimeMsin interfacePAGesture
-
getTimeOffset
public int getTimeOffset() -
setTimeOffset
public void setTimeOffset(int timeOffset) -
getTimeOffsetsMs
public float[] getTimeOffsetsMs()Returns time offsets as floats. First value should be 0, remaining ones are times from 0 in milliseconds.- Specified by:
getTimeOffsetsMsin interfacePAGesture
-
getDragTimes
public int[] getDragTimes()- Returns:
- the list of time data for the gesture captured by dragPoints: The first offset is expected to be 0 and the remaining elements are offsets in milliseconds.
-
getAllTimes
public int[] getAllTimes()getAllTimes() is a convenient alias for getDragTimes()- Returns:
- a list of time offsets, the first one equal to zero
-
setDragTimes
public void setDragTimes(int[] dragTimes) - Parameters:
dragTimes-
-
setDragTimes
-
getReducedTimes
public int[] getReducedTimes() -
getAllPointsSchedule
Description copied from interface:PAGestureConvenience: a schedule over the dense gesture.- Specified by:
getAllPointsSchedulein interfacePAGesture
-
getReducedSchedule
-
getCurveSchedule
-
getDragColor
public int getDragColor() -
setDragColor
public void setDragColor(int dragColor) -
getDragWeight
public float getDragWeight() -
setDragWeight
public void setDragWeight(float dragWeight) -
getRdpColor
public int getRdpColor() -
setRdpColor
public void setRdpColor(int rdpColor) -
getRdpWeight
public float getRdpWeight() -
setRdpWeight
public void setRdpWeight(float rdpWeight) -
getCurveColor
public int getCurveColor() -
setCurveColor
public void setCurveColor(int curveColor) -
getCurveWeight
public float getCurveWeight() -
setCurveWeight
public void setCurveWeight(float curveWeight) -
getBrushColor
public int getBrushColor() -
setBrushColor
public void setBrushColor(int brushColor) -
getBrushWeight
public float getBrushWeight() -
setBrushWeight
public void setBrushWeight(float brushWeight) -
getActiveBrushColor
public int getActiveBrushColor() -
setActiveBrushColor
public void setActiveBrushColor(int activeBrushColor) -
getEventPointsColor
public int getEventPointsColor() -
setEventPointsColor
public void setEventPointsColor(int eventPointsColor) -
getEventPointsSize
public float getEventPointsSize() -
setEventPointsSize
public void setEventPointsSize(float eventPointsSize) -
dragPointsDraw
public void dragPointsDraw(processing.core.PApplet parent, int lineColor, float lineWeight) Draws a line using the PVector data in dragPoints and a supplied color.- Parameters:
parent- a PApplet where drawing takes placelineColor- color for the line that is drawn
-
dragPointsDraw
public void dragPointsDraw(processing.core.PApplet parent) Draws a line using the PVector data in allPoints and the current values of this.dragColor and this.dragWeight.- Parameters:
parent- a PApplet where drawing takes place
-
reducedPointsDraw
public void reducedPointsDraw(processing.core.PApplet parent, int lineColor, float lineWeight) Draws a line using the PVector data in drawPoints, the reduced point set derived from allPoints.- Parameters:
parent- a PApplet where drawing takes placelineColor- the color for the line that is drawnlineWeight- the weight of the line that is drawn
-
reducedPointsDraw
public void reducedPointsDraw(processing.core.PApplet parent) Draws a line using the PVector data in rdpPoints and the current values of this.rdpColor and this.rdpWeight.- Parameters:
parent- a PApplet where drawing takes place
-
dragPointsDraw
public void dragPointsDraw(processing.core.PGraphics pg, int lineColor, float lineWeight) Draws dragPoints to a PGraphics using supplied color and weight.- Parameters:
pg- a PGraphics offscreen graphics contextlineColor- color for the line through the dense point setlineWeight- weight (in pixels) of the line through the dense point set
-
dragPointsDraw
public void dragPointsDraw(processing.core.PGraphics pg) Draws dragPoints to a PGraphics using local color and weight, this.dragColor and this.dragWeight.- Parameters:
pg- a PGraphics offscreen graphics context
-
reducedPointsDraw
public void reducedPointsDraw(processing.core.PGraphics pg, int lineColor, float lineWeight) Draws rdpPoints to a PGraphics using supplied color and weight.- Parameters:
pg- a PGraphics offscreen graphics contextlineColor- color for the line through the reduced point setlineWeight- weight (in pixels) of the line through the reduced point set
-
reducedPointsDraw
public void reducedPointsDraw(processing.core.PGraphics pg) Draws drawPoints to a PGraphics using current values of this.rdpColor and this.rdpWeight.- Parameters:
pg- a PGraphics offscreen graphics context
-
curveDraw
public void curveDraw(processing.core.PApplet parent) Draws a Bezier curve using the 2D Bezier curve data in this.curveShape and the current values of this.curveColor and this.curveWeight. The resulting curve will have no fill.- Parameters:
parent- a PApplet instance
-
curveDrawDirect
public void curveDrawDirect(processing.core.PApplet parent) Draws a Bezier curve using local drawing properties of curveShape. If the drawing properties use a fill, the resulting curve will have a fill.- Parameters:
parent- a PApplet instance
-
curveDraw
public void curveDraw(processing.core.PGraphics pg) Draws a Bezier curve using the 2D Bezier curve data in this.curveShape and the current values of this.curveColor and this.curveWeight. The resulting curve will have no fill.- Parameters:
pg- a PGraphics offscreen graphics context
-
curveDrawDirect
public void curveDrawDirect(processing.core.PGraphics pg) Draws a Bezier curve using local drawing properties of this.curveShape as a PABezShape. If the drawing properties use a fill, the resulting curve will have a fill.- Parameters:
pg- a PGraphics offscreen graphics context
-
brushDraw
public void brushDraw(processing.core.PApplet parent, int brushColor, int strokeColor, float brushWeight) Draws the stored brushShape to a PApplet using supplied fill color, stroke color, and weight. If brushWeight == 0, there is no stroke.- Parameters:
parent-brushColor-strokeColor-brushWeight-
-
brushDraw
public void brushDraw(processing.core.PApplet parent) Draws the stored brushShape to a PApplet using local properties this.brushColor, this.brushColor, this.brushWeight.- Parameters:
parent-
-
brushDrawDirect
public void brushDrawDirect(processing.core.PApplet parent) Draws the stored brush shape to a PApplet using its properties as a PABezShape.- Parameters:
parent-
-
brushDraw
public void brushDraw(processing.core.PGraphics pg, int brushColor, int strokeColor, float brushWeight) Draws the stored brushShape to an offscreen PGraphics using supplied fill color, stroke color, and weight. If brushWeight == 0, there is no stroke.- Parameters:
parent-brushColor-strokeColor-brushWeight-
-
brushDraw
public void brushDraw(processing.core.PGraphics pg) Draws the stored brushShape to an offscreen PGraphics using local properties this.brushColor, this.brushColor, this.brushWeight.- Parameters:
parent-
-
brushDrawDirect
public void brushDrawDirect(processing.core.PGraphics pg) Draws the stored brush shape to an offscreen PGraphics using its properties as a PABezShape.- Parameters:
parent-
-
eventPointsDraw
public void eventPointsDraw(processing.core.PApplet parent) Draws this.eventPoints to a PApplet as circles using local properties this.eventPointsColor and this.eventPointsSize.- Parameters:
parent-
-
eventPointsDraw
public void eventPointsDraw(processing.core.PApplet parent, int eventPointsColor, float eventPointsSize) Draws this.eventPoints to a PApplet as circles using supplied properties eventPointsColor and eventPointsSize.- Parameters:
parent-eventPointsColor-eventPointsSize-
-
eventPointsDraw
public void eventPointsDraw(processing.core.PApplet parent, int eventSteps, int eventPointsColor, float eventPointsSize) Draws this.eventPoints to a PApplet as circles using supplied properties eventPointsSteps, eventPointsColor and eventPointsSize. EventPointsSteps determines the number of circles. The local value eventPointsSteps is not changed.- Parameters:
parent-eventSteps-eventPointsColor-eventPointsSize-
-
eventPointsDraw
public void eventPointsDraw(processing.core.PGraphics pg) Draws this.eventPoints to an offscreen PGraphics as circles using local properties this.eventPointsColor and this.eventPointsSize.- Parameters:
pg-
-
eventPointsDraw
public void eventPointsDraw(processing.core.PGraphics pg, int eventPointsColor, float eventPointsSize) Draws this.eventPoints to an offscreen PGraphics as circles using supplied properties eventPointsColor and eventPointsSize.- Parameters:
pg-eventPointsColor-eventPointsSize-
-
eventPointsDraw
public void eventPointsDraw(processing.core.PGraphics pg, int eventSteps, int eventPointsColor, float eventPointsSize) Draws this.eventPoints to an offscreen PGraphics as circles using supplied properties eventPointsSteps, eventPointsColor and eventPointsSize. Parameter eventPointsSteps determines the number of circles. The local value eventPointsSteps is not changed.- Parameters:
pg-eventSteps-eventPointsColor-eventPointsSize-
-