View Full Version : Draw Sine Wave
Hi all.
I have no experience with action script and I need to draw and animate a sine wave.
Is it possible to tween it?
Can somebody please help?
Thanks in advance.
Peter.
Hi.
Thought I'd post an update.
After a lot of reading and hacking code examples I found on the internet I've got this basic script together to create a moving sine wave.
I've annotated the variables best I can but I'm not exactly sure what 'WAVESTOP' does but you need it in.
You will need to create a MovieClip called 'dot' which will be a filled in circle with a radius of 2 (or whatever you like) - remember to export the symbol for Actionscript when you create it.
Unfortunately I need the waveform to increase in amplitude as it moves towards the right but I don't think its possible with this script so its back to the drawing board.
I'm using Flash Prof 8.
var WaveX:Number = 151; // starting point of wave on x axis
var WaveY:Number = 180; // starting point of wave on y axis
var WaveAmp:Number = 3 // wave amplitude
var Freq:Number = 2.44 // frequency
var WAVESTOP:Number = 297.3;
var angle:Number = 0;
for (var i=0; i<150; i++) { // Draws a waveform 150 pixels long
angle -= (Math.PI/180*2) * Freq;
this.attachMovie("dot", "dot"+i, i, {_x:WaveX+i, _y:WaveY - Math.sin(angle) * WaveAmp});
}
this.onEnterFrame = function() {
for (var i=0; i<150; i++) {
this["dot"+i]._x = (this["dot"+i]._x >= WAVESTOP) ? WaveX : this["dot"+i]._x + 1;
}
}
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.