Lissajous curves are generated by a relatively simple formula
// x = Αsin(at + δ), y = Bsin(bt)
// all angles are in radians
var a = 3; // amplitude/frequency of x
var b = 4: // amplitude/frequency of y
var step = 1 * (Math.PI/180); // 1 degree converted to radians
var delta = 60 * (Math.PI/180); // phase shift converted to radians
for(var angle=0; angle<=(Math.PI*2 + step); angle+=step) {
x = Math.sin( angle*a + delta );
y = Math.sin( angle*b );
}
Try as I might and given my extreme weakness with entry level calculus I couldn't determine the error in the math. Instead I corrected the glitch with a simple function to check whether the control handles of the curve are within an acceptable boundary.
function boundsCheck(pt1, pt2, tolerance) {
var brect = new Rectangle(
new Point(-(pt2.x+tolerance.x), -(pt2.y+tolerance.y)), new Point(pt2.x+tolerance.x, pt2.y+tolerance.y) ); return pt1.isInside(brect); };
new Point(-(pt2.x+tolerance.x), -(pt2.y+tolerance.y)), new Point(pt2.x+tolerance.x, pt2.y+tolerance.y) ); return pt1.isInside(brect); };
Phase Shift
the period of the curve
Frequency
frequency ratio across the x & y axes
Stroke Weight
set two different stroke weights and the curve will interpolate from the start to the end weight
Colors
set two colors and the curve will interpolate from the start to the end color
Opacity
set two opacity values and the curve will interpolate from the start to the end opacity
Blend
blend mode of opacity: normal, multiply, screen, etc.
Flyout Menu:
Alternate
colors will alternate every other segement
Blend
colors will blend across segments from start to end
Mouse drag
modulate the frequency (using the input values as maximums), the closer to the origin of the document = 0, the further away the maximum
Mouse drag+shift
modulate the phase shift (mouse x axis) from 0 - 360
The paperjs version is here and works as described above, grab the scripts/source for scriptographer lissajous.js
Labels: paperjs, scriptographer