Package net.paulhertz.pixelaudio.curves
Class PAGestureParametric
java.lang.Object
net.paulhertz.pixelaudio.curves.PAGestureParametric
PAGestureParametric
Treats a gesture defined by (time, x, y) samples as a parametric curve:
u ∈ [0,1] → (t(u), x(u), y(u))
Under the hood:
- timesMs: int[] of time offsets (ms), ascending, timesMs[0] == 0
- points: PVector list (x,y) of same length
You can:
- sample with a linear parameter: f(u) = u
- pass a warp function f(u) to speed up/slow down traversal
Exponential warp (speeding up over time)
DoubleUnaryOperator expWarp = u -> (float_ Math.pow(u, 2.0); // u^2
GestureParametric.Sample s = gp.sample(0.5f, expWarp);
Log-like warp (fast at start, slow at end)
DoubleUnaryOperator sqrtWarp = u -> (float_ Math.sqrt(u); //
GestureParametric.Sample s = gp.sample(0.5f, sqrtWarp);
Something like f(u) = (e^{k * u} - 1) / (e^{k} - 1) for more dramatic warps.-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final List<processing.core.PVector>private final int[]private final float -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate intfindSegment(float tTarget) Find the largest i such that timesMs[i] <= tTarget.floatTotal gesture duration in ms.private static floatlerp(float a, float b, float u) sample(float u) Sample with linear parameterization: f(u) = u.sample(float u, DoubleUnaryOperator warp) Sample with an optional warp function f(u) → [0,1].
-
Field Details
-
points
-
timesMs
private final int[] timesMs -
count
private final int count -
totalDurationMs
private final float totalDurationMs
-
-
Constructor Details
-
PAGestureParametric
- Parameters:
points- gesture points (x,y)timesMs- time offsets (ms), same length as points, ascending, timesMs[0] == 0
-
-
Method Details
-
getTotalDurationMs
public float getTotalDurationMs()Total gesture duration in ms. -
sample
Sample with linear parameterization: f(u) = u. u is clamped to [0,1]. -
sample
Sample with an optional warp function f(u) → [0,1]. If warp is null, identity is used. -
findSegment
private int findSegment(float tTarget) Find the largest i such that timesMs[i] <= tTarget. Returns count-1 if tTarget is beyond the last sample. -
lerp
private static float lerp(float a, float b, float u)
-