
Basic usage of the moveTo(), lineTo() and clear() drawing methods to generate Lissajous curves in Flash. Drag your mouse horizontally and vertically to change x-y frequencies. These methods were introduced in Flash MX. It is possible to create an almost identical line drawing method in Flash 5 with attachMovie() and line segments.
Download Source File: Flash6_Lissajous.zip
Code:
/* Lissajous figure drawing method
************************************************************/
MovieClip.prototype.createLissajous = function(fx, fy, radius, thickness, color) {
this.clear();
this.lineStyle( (thickness ? thickness : 2), (color ? color : 0xcc0000), 100);
this.moveTo(radius, 0);
var alpha, x, y;
var steps = 40 * fx * fy;
for(var i = 0; i <= steps; i++) {
alpha = 2 * Math.PI * i / steps;
x = radius * Math.cos(fx * alpha);
y = radius * Math.sin(fy * alpha);
this.lineTo(x, y);
}
}
/* Host Movieclip for Lissajous curves
************************************************************/
_global.mc = this.createEmptyMovieClip("_mc", 1);
_global.mc._x = Stage.width / 2;
_global.mc._y = Stage.height / 2;
/* Movieclip to control frequencies
************************************************************/
this.createEmptyMovieClip("control", 2);
this.control._x = 100;
this.control._y = 50;
this.control.onEnterFrame = function() {
var fx = 1 + Math.floor(this._x / 50);
var fy = 1 + Math.floor(this._y / 50);
if(fx != this.fx || fy != this.fy) {
this._parent.fx_txt.text = "fx: " + (this.fx = fx);
this._parent.fy_txt.text = "fy: " + (this.fy = fy);
_global.mc.createLissajous(fx, fy, 150, 3, 0xcc0000);
}
}
this.control.onMouseDown = function() {
this.startDrag(false, 0, 0, 250, 250);
}
this.control.onMouseUp = function() {
this.stopDrag();
}