VDistance
Computes the distance between two vectors
See also: VLength
Description
VDistance computes the distance between two vectors by calculating the length of their difference, essentially VLength.pr(v - u)
.
Supported Rates: frame, shape, pixel
Class Methods
VDistance.fr(u, v)
VDistance.sr(u, v)
VDistance.pr(u, v)
Make a VDistance VGen at the requested rate
Arguments
u
First vector input for distance computation.
v
Second vector input for distance computation.
Returns:
The distance between u and v.
dimensions
input |
output |
1, 1 |
1 |
2, 2 |
1 |
3, 3 |
1 |
4, 4 |
1 |
Examples
(
// This example uses the Distance operator to plot the distance at each pixel to the
// moving point on three different Lissajous curves, one in each color channel.
// The dot parameter controls the size of the dot around each curve, by scaling how
// quickly the dot will drive the length to the clamp values as distance from each
// Lissajous point increases.
~k = ScinthDef.new(\k, { |dot = 0.5|
var rx = VSinOsc.fr(freq: 1.5, mul: 0.9, add: 0.0);
var ry = VSinOsc.fr(freq: 1, phase: pi / 4, mul: 0.9, add: 0.0);
var gx = VSinOsc.fr(freq: 0.5, phase: pi / 2, mul: 0.9, add: 0.0);
var gy = VSinOsc.fr(freq: 1.25, mul: 1.0, add: 0.0);
var bx = VSinOsc.fr(freq: 0.75, phase: pi / 3, mul: 0.9, add: 0.0);
var by = VSinOsc.fr(phase: 3 * pi / 4, mul: 0.9, add: 0.0);
var pos = VNormPos.pr;
var r = VClamp.pr(1.0 - (VDistance.pr(VVec2.fr(rx, ry), pos) / dot), 0.0, 1.0);
var g = VClamp.pr(1.0 - (VDistance.pr(VVec2.fr(gx, gy), pos) / dot), 0.0, 1.0);
var b = VClamp.pr(1.0 - (VDistance.pr(VVec2.fr(bx, by), pos) / dot), 0.0, 1.0);
VRGBOut.pr(r, g, b);
}).add;
)
(
~t = Scinth.new(\k);
)
Last modified July 28, 2020: Update for a 0.0.7 Scintillator release (#5) (0177d81)