Here is a slight modification:
What will be next steps?
var mc = this.createEmptyMovieClip( "mc", 11);
onEnterFrame = function ()
/*
t - time
(x,y)
*/
{
var t = getTimer()/1000; //100
var x0=0, x1 = Math.PI*10;
var imax = 100;
var xy = getData( this, myFunction, x0, x1, t, imax);//
drawLine (mc, xy);
}
// ------
function myFunction ( x, t)
{
return x*Math.sin(x*t)
}
// --
function getData ( this_o:Object, func:Function, x0 :Number, x1 :Number,
t:Number, imax :Number) :Array
{
var x, dx = (x1-x0)/(imax-1);
var xy = new Array ();
for (var i=0; i<imax; i++) {
x = x0 + i*dx;
xy[i] = {x:x, y: func.call( this_o, x, t)}
}
return xy;
}
// --
function drawLine ( mc:MovieClip, xy :Array)
{
mc.clear();
mc.lineStyle(0, 0, 100);
mc.moveTo( xy[0].x, xy[0].y);
var imax = xy.length;
for (var i=1; i<imax; i++)
{
mc.lineTo( xy[i].x, xy[i].y);
}
}
----- Original Message -----
From: "Martin Wood" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <[email protected]>
Sent: Friday, February 17, 2006 6:14 PM
Subject: [Bulk] Re: [Flashcoders] seeking :: Oscillating SineWaves via
Drawing API
its quick and its dirty but it should give you something to work with :
for(var n=0;n<3;n++)
{
var sinewave:MovieClip = _root.createEmptyMovieClip("sinewave" + n,n+1);
sinewave._y = 100;
sinewave.phase = n * 10;
sinewave.frequency = ((n + 1) * 5) / 50;
sinewave.amplitude = 60 - (n * 10);
sinewave.speed = (n + 1) / 5;
sinewave.heightDeviation = Math.random() * 30;
sinewave.onEnterFrame = function()
{
this.phase+=this.speed;
_root.drawSineWave(this,this.phase,this.amplitude + (Math.sin(this.phase)
* this.heightDeviation),this.frequency);
}
}
function drawSineWave(mc:MovieClip, phase:Number, amplitude:Number,
frequency:Number)
{
var numPoints:Number = 80;
var width = 550;
mc.clear();
mc.lineStyle(2,0,100);
var y:Number = Math.sin(phase * frequency) * amplitude;
mc.moveTo(0,y);
var dx:Number = width / numPoints;
for(var x=0;x<numPoints;x++)
{
y = Math.sin((phase + x) * frequency) * amplitude;
mc.lineTo(x * dx,y);
}
}
you can just stick this into the first frame of an .fla
let me know if you need some explanations.
thanks,
Martin
artur wrote:
its 3 waves that need to appear randomly oscillating in height..
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com
_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders
Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com