Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
  Advanced Search
  HOME    TRACKER    Flash




How To Calculate The Angle Of A Sine (or Cosine)?



i have a problem with something i supposed to remember from the old math from school, but i forgot..

Im fixing a MC wich moves towards a certain point, (lets say, a anti aircraft missile), its dynamic, so it also follows a moving point. (see this thread: http://board.flashkit.com/board/show...32#post1392132 )

That works, i measure the distance (X and Y) to the target point, combine that to total distance, and do some math to get the sine or cosine of the angle between the two point's

All fine, BUT i dont know how to get the angle (in radians or degree's) from the sinei/cosine i calculated.. and i need that to align the moving movieclip to its path(otherwise it looks crap, eg: a missile that moves while pointing right while moving sideways)

I can calculate allmost everything with right-triangles exept this.. so help me please; this seems one of those things that come back all the times when scripting game gfx..

So the question is: how to calculate an angle out of a sine or cosine??

Macaca
[Edited by Macaca on 01-01-2002 at 11:41 AM]



FlashKit > Flash Help > Flash ActionScript
Posted on: 12-30-2001, 07:02 AM


View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread

Move Direction On Angle - Sine And Cosine
Hey, I am having a lot of trouble with this. I have a ball and a platform. Now when I press left and right keys, the platform will rotate, to a max of 30 degrees right and left. The ball is constantly falling, coded at a rate so that it is like gravity...here is the code for it:

code: onClipEvent (load) {
time = 0;
}

onClipEvent (enterFrame) {
//implement gravity into the ball
_y = 1/2*(.2)*Math.pow(time, 2);
time++;
}

Now the code for when the ball hits the platform (it is coded like this because in reality, there are multiple paddles):

code: onClipEvent (enterFrame) {
with (_root.ball) {
//maze boundaries
if (leftPad.row3.hitTest(_x, getBounds(_root).yMax, true)) {
time --;
}
}
}

Now, what I want to do is make is so that, depending on the angle of the platform, the ball's x and y will fall in the correct direction at the correct rate. I figure I will have to use sine and cosine for this, but I am not wholly sure how to get it to work.

All I did so far was calculate the sine and cosine, but I don't know exactly how to impliment it into the movement of my ball...

code: angle = _root.maze._rotation;
//how much the maze has rotated
currentX = Math.cos(angle*Math.PI/180);
currentY = Math.sin(angle*Math.PI/180);
(it is within an onClipEvent handler)

Any help would be greatly appreciated, thanks

Need Sine And Cosine Help
FIrst off i have a piece of code which makes an mc
"bounce" up and down:
_y = -Math.abs(100*Math.sin(_x/75))
I understand the absolute value part and everything else except for the sin part. I understand a little about sine and cosine when using it so make an object move based on its rotation, but i dont understand how this code works. THe x is constantly being increased by another line of code, but if you multiply the sine times the x wouldn't the y just keep going up? I dont understand what makes the ball peak and then come back down.

can anyone help explain this in simple terms and/or show me some links which help explain sine and cosine? THanks in advance.

Sine And Cosine Help
HELLO! I LL TRY USE Math.sin(x:Number); but the results is wrong.
sees the images and anyone can help me ?
i wanna calculate the sine and co-sine of angle numbers.

tks

Sine/Cosine Question
if i have an angle of 140 and i take the cosine and sine of it.

angle = 140;
thesine = Math.sin(angle);
thecosine = Math.cos(angle);

It is returning random numbers sometimes they're both positive or both negative or one of each. Does anyone know why this is happening.

thanks in advance

khamstra

[F8] Using Variable In Cosine/sine
I made a couter that raises the value of "step" by 1 each time the frame is loaded. The scene is nothing more than a looping timeline of 13 frames. (the first frame sets "step" to zero). I can see the couter works, in a dynamic textfield.

Now i'm trying to use this variable in a cosine&sine function so that i have a rotating object as a function of time.

The function:

onClipEvent (load) {
_x = 180*Math.cos((2*Math.PI*step)/225)+400;
_y = 180*Math.sin((2*Math.PI*step)/225)+400;
}

But this doesn't seem to work, my object doesn't move, while my counter is happily counting. What am I to do here?

HELP How Do I Plot Sine & Cosine Graph Using Related Formulas
i need help on plotting sine & cosine graph

Cosine Function To Find Angle Of Robots Arm For My Game. EASY?
Ok heres the deal...

I am making a megaman style game. I am currently making a Boss. The boss has an arm that needs to rotate to point at your charactor, to shoot his gun. Right now I have a script I wrote that gets the diference in X's for sideB of the triangle and Distant in Y's for sideC and the pathagoreon therom to get sideA. All the sides are correct.

Now for the rotation, I am finding angle A (opposite of sideA) which is the hypotinues.

The function for cosine is: A = acos(b2 + c2 - a2) / (2bc)....Heres my code. Please tell me what I did wrong for the angela. Thanks in advance.

::SCRIPT::

onClipEvent (enterFrame) {
_root.sideb = _root.pos2._x - _root.robotout._x;
_root.sidec = _root.pos2._y - _root.robotout._y;
_root.sidea = math.sqrt(_root.sideb*_root.sideb + _root.sidec*_root.sidec);
_root.anglea = Math.acos((_root.sideb*_root.sideb + _root.sidec*_root.sidec - _root.sidea*_root.sidea) / (2*_root.sideb*_root.sidec));
this._rotation = _root.anglea;
}

About Calculate Angle Question Thanks
Hi


Quote:




x = _xmouse;
y = _ymouse*-1;
angle = Math.atan(y/x)/(Math.PI/180);




any other method to calculate?
my math concept is poor......


thanks....

Calculate Angle & Distance
Does anybody know where I can find code to do this:
http://www.albinoblacksheep.com/flash/bowman.php ?

About Calculate Angle Question Thanks
Hi
x = _xmouse;
y = _ymouse*-1;
angle = Math.atan(y/x)/(Math.PI/180);

any other method to calculate?
my math concept is poor......

thanks....

Calculate An Angle Based On 4 Points
Hello everyone.. Im making a game, but i need to know how to calculate the angle of a line based on the x and y coordinates of the top and bottom points. If anyone knows how to do this, i would greatly apprciate your help.

Calculate The Angle Between 2 Movie Clips
Hi guys!
How can I calculate the angle made by 2 movie clips. Each one representing a line.
Thanks,

Using An Object Angle To Calculate X & Y Values
I need to move an object forward at the angle that it's pointing. Say you want a ship to move forward based on it's angle - the ship has x and y coordinates (lets say shipx and shipy), an angle (say shipangle) and a speed (shipspeed): some maths has to be done to create a new position each time. I figured out a long-winded way of doing it but I think there should be a simple equation I don't know yet (maybe something to do with sines and copsines?).

Thanks in advance.

[F8] Calculate Rotation Angle Using Atan2
With the ZigoEngine I have created a random movement function with a random bezier. This works fine, but I want to rotate my moving MC according to the direction my movieclip is moving. I know this can be done with the Math.atan2 method, but don't know hos to use this.

My code so far:


Code:
function randomX():Number{
return (Math.round(Math.random() * Stage.width)) + (Math.round(Math.random() * (owerflow-(owerflow/2))));
}

function randomY():Number{
return (Math.round(Math.random() * Stage.height)) + (Math.round(Math.random() * (owerflow-(owerflow/2))));
}

function randomScale():Number{
return Math.round(Math.random() * 30 + 30)
}

function moveButterfly():Void{
m.destX = randomX();
m.destY = randomY();
var f:Fuse = new Fuse();
f.push({target:butterfly_mc, scale:randomScale(), x:destX, y:destY, controlX:destX, controlY:destX, time:5, ease:'easeInOutQuad'});
f.push({func:moveButterfly});
f.start();
}
Can anyone help?

Calculate _rotation(angle) Out Of 2 Positions
i have an mc with its current ._x and ._y and i set (randomly) a new x and y position(so i have a triangle with the 2 positions) . now i want my mc to rotate until it faces the new x and y. when i have the angle(_rotation) i can use the following script to get to the new position.

var radius:Number = angle*Math.PI/180;
tank._x -= Math.cos(radius)*distance;
tank._y -= Math.sin(radius)*distance;

how can i calculate the angle (_rotation) out of the triangle(my math isn't the best at the moment...)?

Sin, Cosine And Tan
Waddap peoples!

Ok, I have built a graphing application that draws Sin, Cosine and Tangent curves.
Problem is, when I run it in FP7, it works beautifully, but when viewed in FP8, the TAN graph is all broken... I get two solid lines down the middle of 90 and -90 degrees (Which we all know cant be true).

I use lineTo to construct the curves. Is there a problem with the way Flash calculates Tan in FP8? Or will I have to write an exception for 90 and -90; could it be that when it does the lineTo to the next point on the Tan curve, it draws from the last point on to the almost infinite point, hence making a seemingly straight line?

Thanks. Attached are screenshots of the two scenarios.

I think there might be a flaw in my code... Anyone have this before?

Inverse Cosine
I'm trying to compute a set of angles using the inverse cosine. I can't seem to figure out if this is built in to MX or not. I know that there's a bunch of new Math functions, but I can't find the inverse cosine.

If it doesn't exist, does anyone know of a way to compute the inverse cosine using the existing Math functions?

Thanks.

Little Help With Cosine Wave?
as you can see: http://entropy.randomstupidity.com/cosinewave.html the last ball has almost an oposite cosine value, or the _x didn't get turned into radian. here's the code. maybe someone could lend a little hand?

bnum = 19;//number of balls
bspace = 13; //space between the rightmost ball and the rightedge
rightedge = 550;//right edge of the stage
leftedge = 0;//left edge of the stage
topedge = 0;//topedge of the stage
bottomedge = 400;//bottomedge of the stage

//it's loop time, everybody!
for(i=0; i<bnum; i++){
if(!i){ //this part only declared the first time around the loop
xorigin = rightedge-10;
yorigin = topedge+200;
}

attachMovie("ballclip", 'b'+i, i, {_x: xorigin-bspace});
thisB = _root["b"+i];
thisB.onEnterFrame = moveMe;
xorigin=xorigin-28;
}

function moveMe(){
this._y= yorigin+x;
amplitude=_ymouse/2-100;
x=Math.cos((this._x+_xmouse)*(Math.PI/180))*amplitude;
}

Help With Animated Cosine Wave
Hi all,

can anyone help me with an effect that i am trying to create.

I want to create a cosine wave that moves accross the screen horizontally. However the wave has circles attached to it that i want to move on the y axis inline with the wave but not on the x axis. i can do both seperatly bu not together.

Any help would be greatly appreciated. Math is not my strong point.

Cheers Rikki

www.flamedia.co.uk

DCT (Discrete Cosine Transformation)
I want to do a DCT on a bytearray, which is built from a bitmap in AS 3.0. Unfortunately I am not very good at the more complex math. So I am kind of at a loss where to begin.

My main purpose for this is I am trying to setup streaming webcam functionality using a socket server, and unfortunately, it's not the easiest to do streaming stuff if you're not using media server/net connection/net stream.

Any other guidance or feedback would be greatly appreciated, or anything other ways to streamline the feed, (I am already aware of compressing the byte array).

Inverse Sine
anyone know if there is an inverse sine function? i have two squares with a line in between them and i have to rotate it so that it correlates with the position of the squares.

anyone have any ideas? thanks, patrick.

Sine Like Waves
I'd like to know how to make sine like waves (see link), I want them to move and oscilate randomly but with long intervals...Anyone know how> I'm a complete flash newb and just want to make this for an opening to my site...

http://www.cs.odu.edu/~cpoyner/wavering.gif

Thanks

SINE CURVE?
hi guys..why does the sine curve in the math.sin function start by going down...i am having real problems with that.i am applying that function at the origin and i want it to start the normal way by going in the positive y direction .can i somehow get it to start going upwards ?? Please help!!

Using Sine For Rotation
I'm trying to do something in DHTML (Javascript), which I'm sure many of you will have done in actionscript.

It's not really the language I'm having problems with, it's the method.

http://www.dannytuppeny.com/spin.asp

It's supposed to be travelling in a circle, but it looks naff. If you view the source, you'll see what I'm trying. If anyone can explain what's wrong, it'd be greatly appreciated.

If you have any questions about it, post here and I'll answer

Thanks,

Danny

Sine Function
how do i use the math.sin funtion. I have a symbol that i want to go in a wavy motion like a sin graph.

Sine Wave
I'm trying to just draw a static sine wave on the stage. How do I do this? I've seen some that map dots to the Math.Sine function, but I'm trying to do it with a line or path...I need to see some code, though. I'm new to Actionscripting, so dots or lines or whatever is fine. Would appreciate the help.

Sine Conversion
So i'm writing some code and I need to have the sine of an angle in degrees. I can only get it in radians with flash. What can I do?

[F8] Sine Wave Help
I want to create a background like on the psp and ps3 but I cant figure out how to animate the waves. How could i do this?

Ask Some Help With Sine Wave
i use this .fla
and try to make it changing colours.....
like gradient, changing colours non-stop(look like equalizier)

sorry i'm a newbie pls help

thx for anyone who helping me!!!!!!!!!!!!!!

Movement Using Sine
Hi
i have created a small animation using motion tweening and i was wondering if the same animation could be recreated using action script
here it is
http://www.mn001c7645.pwp.blueyonder.co.uk/sine.html

Sine Curves
Hi

I want to be able to input the start screen co-ordinates and the destination co-ordinates and plot a sine curve between them.

So for example. I may wish to start at 100,100 on the screen and end at 150,150. I want to plot a sine curve between these 2 points.

The formula I use to plot a sine curve is

x=x+1;
y=y-sin(degrees)*radius;


The question I have is is it possible to create a formula which plots a sine curve which hits 2 given points.

Movement Using Sine
Hi
i have created a small animation using motion tweening and i was wondering if the same animation could be recreated using action script
here it is
http://www.mn001c7645.pwp.blueyonder.co.uk/sine.html

Animated Sine Wave
Hi I wonder can anyone help.

I want to create a spectrum analyser with several grpahical elements one of them being a sine wave. the analyser is a real one using generater vars from swiftmp3. Havent got in to actionscript too much so Im not sure where the best place to start is. Would this be something totally generated by math continuously or some kind of programmatic animation of bezier curves.

Please help

Pete

Sine Wave Stuff
I'm trying to put together an interactive sine wave generator where the user can input amplitude and frequency values and have an animated sine wave on the screen display the corresponding amplitude and wavelength. So to that end, I'm trying to accomplish any of the following:

Draw a static sine wave (amplitude 1, WL=2Pi) on the screen, ideally without using a bunch of dots mapped to a sine function. Any way to do it with a line/path?

Create the input text to accomplish this.

Animate the sine wave in a box on the stage and have it "loop" easily.

Any help greatly appreciated

Many IF Statements Or One Sine Statement?
Hi, for my game i have a rotating man that moves in one of 16 directions. Now would it be better (in performance terms) to use 8 IF statements to control his movement or just one Sine calculation??

Bit of a conumdrum for me...

Inverse Sine Function
I'm not exactally a newb to flash, but I feel like one right now. I am trying to make a gravity program and in order to calculate angles, I'm trying to do something that requires the inverse sine of something, and I can't find that function in the Math class. Is it just the Math.asin... I'm not sure. Any help would be great.

Sine Wave Animation
Hello from Germany

at first sorry for my bad english i hope you can help me anyhow

i am trying to animate some sine waves with actionscript, during my research i have found the great code from hgseib (Link: http://www.seibsprogrammladen.de/fra...ispiele/flash6 -> Zeichnen ...Sinuswelle). The script works very well but it slows down hardly my computer if i animate 3 or more waves in that way. My question: has someone of you any ideas to optimize the script from hgseib or another script wich makes the same?


Code:
var cBogenmass = Math.PI/180;
var cHoch = 106;
var cLinks = 0;
var cRechts = 628;
var cStepps_pro_draw = 230;
var cVorschub = (cRechts-cLinks)/cStepps_pro_draw; //ca. 2.7
var cDreh_pro_time = 2*cBogenmass;//Halbwellen
var cDreh_pro_draw = 1*cBogenmass;//Geschwindigkeit
var cRadius = 50;
// globale
var gDaempfung = 0.99;
var gDrehung = 0;
//

_root.paint_mc = _root.createEmptyMovieClip('welle4', _root.getNextHighestDepth());
_root.paint_mc = _root.createEmptyMovieClip('welle3', _root.getNextHighestDepth());
_root.paint_mc = _root.createEmptyMovieClip('welle2', _root.getNextHighestDepth());
_root.paint_mc = _root.createEmptyMovieClip('welle1', _root.getNextHighestDepth());

_root.attachMovie("balken","balken",_root.getNextHighestDepth());
_root.balken._x = 0;
_root.balken._y = Stage.height - _root.balken._height;



function fSinuswelle(vDrehung,farbe,staerke,nr,cRadius)
{
with (_root["welle"+nr])
{
clear();
var r = cRadius;
var y = cHoch+r*Math.sin(vDrehung);
var x = cLinks;

lineStyle(staerke, farbe, 100);
moveTo(x, y);
for (var vTime = 0; vTime<cStepps_pro_draw; vTime++)
{
vDrehung += cDreh_pro_time;
r *= gDaempfung;
y = cHoch+r*Math.sin(vDrehung);
x += cVorschub;
lineTo(x, y);
}
}
}

_root.onEnterFrame = function() {

gDrehung+= 0.05;
fSinuswelle(gDrehung,0xffffff,3,1,cRadius);
fSinuswelle(gDrehung,0xdddddd,2,2,cRadius+30);
fSinuswelle(gDrehung,0xcccccc,1,3,cRadius+60);
fSinuswelle(gDrehung,0xcccccc,0.5,4,cRadius+90);
};

Sine Curve Animation
Hi, I love the curve animation like this page
http://www.sennheiser.com/sennheiser...f/root/private

then I try to figure out my way...

I guest. I am in a wrong way... in term of flexibility and optimizability
I hope It can be more lively like a rope with the lost of strength....
then I am really in a wrong way of developing the script...


ActionScript Code:
package {

    import flash.display.Sprite;
    import flash.events.TimerEvent;
    import flash.utils.Timer;
    import flash.display.CapsStyle;
    import flash.display.LineScaleMode;

    import flash.text.TextField;

    public class SineAnimation extends Sprite{

        private var tracer:TextField = new TextField();

        public function SineAnimation():void{
            addChild(tracer);


            var moveTimer:Timer=new Timer(10);
            moveTimer.addEventListener(TimerEvent.TIMER,onTimer);
            moveTimer.start();


        }      

        public function drawCurve( phase:Number = 0, waveWidth:Number = 0, amplitude:Number = 100 , sineMcWidth:Number = 0):void{
//      tracer.text=stage.stageWidth.toString();

            if (sineMcWidth == 0)
            {
                sineMcWidth  = stage.stageWidth;
            }
            var offsetY:Number = stage.stageHeight/2;
            var sineCurrentPointX:Number;
            var currentDelta:Number;

            var resultCurve:Sprite = new Sprite;


                graphics.clear();
                graphics.lineStyle(1, 0x990000, 1, false, LineScaleMode.NONE, CapsStyle.SQUARE);
                graphics.moveTo(-20 ,offsetY );


            for( var i:Number = 0; i < sineMcWidth; i++ ) {

                currentDelta = Math.PI * i / 100*waveWidth +  phase ;
                sineCurrentPointX = offsetY + amplitude * Math.sin(currentDelta);
                graphics.lineTo( i , sineCurrentPointX );
       
            }
        }


        public function onTimer( e:TimerEvent  ):void{
   
            drawCurve(e.target.currentCount/100, 0.09);
        }
    }
}

Sine Wave Problem
ok, i am trying to create a rightward moving sine wave with a fill underneath it, so it looks like a ripple. my problem is for some reason, i can get it to move leftward, but when i try to invert it, i get the bottom right hand corner up in the middle.

here's my code:

NbrControlPoints = 20;
StartX = 0;
EndX = Stage.width;
BottomY = Stage.height;
WaterLevel = Stage.height/2;
WaveHeight = 30;
WaveSpeed = .0005;

_root.onEnterFrame = function()
{
this.clear();
this.beginFill(0xFE9919, 100);
this.moveTo(StartX, BottomY);
for (x = 0; x < NbrControlPoints; ++x)
{
var r = x/(NbrControlPoints-1);
px = EndX + r*(StartX - EndX);
py = WaterLevel + WaveHeight*Math.sin(r*Math.PI*2 + getTimer()*WaveSpeed);
this.lineTo(px,py);
}
this.lineTo(StartX, BottomY);
this.lineTo(EndX, BottomY);
this.endFill();
}

and i missing something stupid that is making this happen? i've been troubleshooting this for 2 hours and the math is now making my head hurt.

any help would be appriciated.

Sine Wave To Stop At Target
Hi guys wondered if someone can help me with this problem.
I am trying to get a shape to move in a sine wave path to another target shape. when reached it will stop at the coordinates of the target shape but I don't know how to go about it can anyone help.
thanks in advance

How To Build Sine Waves With Little Cpu Effort?
Hi, guys...

I am looking for a tutorial or source code that dynamically draws a couple of horizontally moving sine waves. I´ve found some sources, but they seem to be very cpu intensive... Does anyone know how to do it with little cpu effort?

Thanks in advance!

Harmonic Effects On A Sine Wave
I had posted a portion of this a couple of days ago but thought I would post the rest in case it might be useful. I hope all the code gets attached. It is helpful for demonstrating the effects of harmonic content in a power system on the sine wave. The individual harmonic percentages are expressed as a percentage of the fundamental (sine wave). I am attaching the script in parts because Attach Code will not let me attach it all in one go.

Here are the first 400 lines







Attach Code

//This is designed for MX 2004
//I think the movie works best at about 30 fps
fscommand("allowscale",true);
fscommand("fullscreen",true);

mouse_listener = new Object();
mouse_listener.onMouseDown = function() {
recalculate_THD();
movesliders();
}
Mouse.addListener(mouse_listener);
//update the harmonics array based on the digital input
//redisplay that digital input with the correct number of decimal places
//calculate the sum of the individual harmonics and update the display
//update the THD display value
//
function recalculate_THD() {
total_harmonic_distortion = 0;//initialize this variable
for(var i = 1; i < harmonics.length; i++) {
harmonics[i]["myamount"] = Number(this.sliders["digital" + i].text_holder.harmonic_percent.text)/100;
this.sliders["digital" + i].text_holder.harmonic_percent.text = String(limit_decimals(Number(harmonics[i]["myamount"])*100));
total_harmonic_distortion = total_harmonic_distortion + Number(harmonics[i]["myamount"]) * Number(harmonics[i]["myamount"]);
}
total_harmonic_distortion = Math.round(Math.sqrt(total_harmonic_distortion)*10000)/100;
this.harmonicsdata["harmonics_value"].text = String(total_harmonic_distortion);
}

//resposition the slider buttons according the the harmonic percentages currently contained in the array
function movesliders() {
for(var i = 0;i < harmonics.length; i++) {
this.sliders["button" + i]._y = -harmonics[i]["myamount"]*100;
}
}

function update_digital_input() {
for(var i = 1; i < harmonics.length; i++) {
this.sliders["digital" + i].text_holder.harmonic_percent.text = String(limit_decimals(Number(harmonics[i]["myamount"])*100));
}
}

function sinewaves_defined_enterframe() {
this._parent._parent.sine.sinewave.onEnterFrame = function() {
if(this.i >= this._parent._parent.res*10) {
this.i = 0;
}
var current_x = this.i;
update_xy_array (current_x);
this._parent._y + add_harmonics(current_x) * my_yscale / 100;
this.i++;
}
}

function add_harmonics(i_value) {
my_yvalue = 0;
for(var k = 0; k < harmonics.length; k++) {
my_yvalue = my_yvalue + 100 * Math.sin(2*Math.PI*i_value*Number(harmonics[k]["myorder"])/res)*Number(harmonics[k]["myamount"]);
}
my_yvalue = my_yvalue * 0.8;
return(my_yvalue);
}

function update_xy_array (currentvalue) {
//push the latest value onto the array
calculated_xy_pairs.push({myx:String(currentvalue),myy:String(add_harmonics(currentvalue))});
//if the length of the array is longer thanthe display area is wide, knock off the first element of the array
if(calculated_xy_pairs.length*my_xscale > oscope._width) {
calculated_xy_pairs.shift({myx:String(currentvalue),myy:String(add_harmonics(currentvalue))});
}
//clear the line and redraw it
sine.sinewave.clear();
sine.sinewave.lineStyle(1,0x00FF00,100);
for(var i = 0; i < calculated_xy_pairs.length-1; i++) {
sine.sinewave.moveTo((-calculated_xy_pairs.length+i)*(my_xscale),Number(calculated_xy_pairs[i]["myy"]));
sine.sinewave.lineTo((-calculated_xy_pairs.length+i+1)*(my_xscale),Number(calculated_xy_pairs[i+1]["myy"]));
}
}

function makeslider(mypath,number_of_sliders,color1,color2,linecolor,slotcolor,leftmargin,mylabels) {
var mylabels,slotcolor;
var mypath,number_of_sliders,mywidth,leftside,rightside,topside,bottomside,slider_x,color1,color2,linecolor,leftmargin;
var my_format:TextFormat = new TextFormat();
my_format.color = linecolor;
my_format.font = "Arial";
my_format.size = 14;
my_format.align = "center";

my_digital_format = new TextFormat();
my_digital_format.bold = true;
my_digital_format.align = "right";
my_digital_format.font = "Arial";
my_digital_format.color = 0x000000;
my_digital_format.underline = false;
my_digital_format.size = 14;
my_digital_format.italic = false;

mypath._xscale = 60;
mypath._yscale = 50;

mypath.createEmptyMovieClip("scale",mypath.getNextHighestDepth());
pixels_between_sliders = 40;
leftside = -10-leftmargin;
rightside = -10 + pixels_between_sliders*number_of_sliders;
topside = -125;
bottomside = 55;
slider_x = 0;

with (mypath.scale) {
//left side
colors = [color1, color2];
alphas = [100, 100];
ratios = [0, 0xFF];
matrix = {matrixType:"box", x:0, y:-120, w:30, h:150, r:(90/180)*Math.PI};
beginGradientFill("linear", colors, alphas, ratios, matrix);
moveTo(leftside-leftmargin,bottomside-5);
lineTo(leftside-leftmargin,-120);
curveTo(leftside-leftmargin,topside,leftside-leftmargin+5,topside);
lineTo(rightside-5,topside);
curveTo(rightside,topside,rightside,topside+5);
lineTo(rightside,bottomside-5);
curveTo(rightside,bottomside,rightside-5,bottomside);
lineTo(leftside-leftmargin+5,bottomside);
curveTo(leftside-leftmargin,bottomside,leftside-leftmargin,bottomside-5);
endFill();

for(var j = 1; j < number_of_sliders; j++) {
slider_x = slider_x + pixels_between_sliders;
lineStyle(0,linecolor,0);
beginFill(slotcolor,100);
moveTo(slider_x-1,0);
lineTo(slider_x-1,-100);
lineTo(slider_x+1,-100);
lineTo(slider_x+1,0);
lineTo(slider_x-1,0);
endFill();
lineStyle(0,linecolor,100);
moveTo(slider_x-1,0);
lineTo(slider_x-1,-100);
moveTo(slider_x+1,0);
lineTo(slider_x+1,-100);
for(var i = 0; i <= 10; i++) {
lineStyle(1.5,linecolor,100);
moveTo(slider_x+6,-i*10);
lineTo(slider_x+12,-i*10);
}
for(var i = 0; i <= 9; i++) {
lineStyle(1,linecolor,100);
moveTo(slider_x+6,-i*10-5);
lineTo(slider_x+10,-i*10-5);
}
}
}
for(var j = 1; j < number_of_sliders; j++) {
mypath.createTextField("buttonlabel" + j,mypath.getNextHighestDepth(),j*pixels_between_sliders-15,-120,33,23);
mypath["buttonlabel" + j].setNewTextFormat(my_format);
mypath["buttonlabel" + j].selectable = false;
mypath["buttonlabel" + j].text = mylabels[j];
my_format.size = 13;
mypath["buttonlabel" + j].setTextFormat(mypath["buttonlabel" + j].text.length - 2,mypath["buttonlabel" + j].text.length,my_format);
my_format.size = 16;

mypath.createEmptyMovieClip("digital"+j,mypath.getNextHighestDepth());
mypath.createEmptyMovieClip("button"+j,mypath.getNextHighestDepth());

mypath["digital" + j]._x = j*pixels_between_sliders;
mypath["digital" + j]._y = 40;
mypath["button" + j]._x = j*pixels_between_sliders;
with (mypath["digital" + j]) {
//make_a_rectangle(this,0x000000,CAF9CC,100,100,0,-10,10,-5,1);
lineStyle(0,0x000000,100);
beginFill(0xCAF9CC,100);
mywidth = 38;
myheight = 20;
moveTo(-mywidth/2,-myheight/2);
lineTo(-mywidth/2,myheight/2);
lineTo(mywidth/2,myheight/2);
lineTo(mywidth/2,-myheight/2);
lineTo(-mywidth/2,-myheight/2);
createEmptyMovieClip("text_holder",1);
text_holder._x = -4;
text_holder._xscale = 90;
text_holder._yscale = 120;
text_holder.createTextField("harmonic_percent",1,-mywidth/2,-myheight/2,mywidth+6,myheight);
text_holder.harmonic_percent.setNewTextFormat(my_digital_format);
text_holder.harmonic_percent.text = "0.00";
}
with (mypath["button" + j]) {
my_button_number = j;
//left side
colors = [0xEEEEEE, 0x666666];
alphas = [100, 100];
ratios = [0, 0xFF];
matrix = {matrixType:"box", x:0, y:0, w:8, h:36, r:(90/180)*Math.PI};
beginGradientFill("linear", colors, alphas, ratios, matrix);
//lineStyle(0,0xFF0000,100);
moveTo(-4,-18);
curveTo(-4,-22,-5.5,-25);
lineTo(-5.5,25);
curveTo(-4,22,-4,18);
curveTo(-6,0,-4,-18);
endFill();
//right side
colors = [0x999999, 0x222222];
alphas = [100, 100];
ratios = [0, 0xFF];
matrix = {matrixType:"box", x:0, y:0, w:8, h:36, r:(90/180)*Math.PI};
beginGradientFill("linear", colors, alphas, ratios, matrix);
//lineStyle(0,0xFF0000,100);
moveTo(4,-18);
curveTo(4,-22,5.5,-25);
lineTo(5.5,25);
curveTo(4,22,4,18);
curveTo(6,0,4,-18);
endFill();
//lineStyle(0,0xFF0000,0);
colors = [0x666666, 0xD5D5D5];
alphas = [100, 100];
ratios = [0, 0xFF];
matrix = {matrixType:"box", x:0, y:-20, w:8, h:36, r:(90/180)*Math.PI};
beginGradientFill("linear", colors, alphas, ratios, matrix);
moveTo(-4,-18);
lineTo(4,-18);
curveTo(6,0,4,18);
lineTo(-4,18);
curveTo(-6,0,-4,-18);
endFill();
colors = [0x666666, 0xCCCCCC];
alphas = [100, 100];
ratios = [0, 0xFF];
matrix = {matrixType:"box", x:0, y:-25, w:8, h:4, r:(90/180)*Math.PI};
beginGradientFill("linear", colors, alphas, ratios, matrix);
lineStyle(0,0xCCCCCC,100);
moveTo(-4,-18);
curveTo(-4,-22,-5.5,-25);
lineStyle(0,0x666666,100);
lineTo(5.5,-25);
lineStyle(0,0xFFFFFF,100);
curveTo(4,-22,4,-18);
lineStyle(0,0x666666,100);
lineTo(-4,-18);
endFill();
colors = [0x999999, 0x000000];
alphas = [100, 100];
ratios = [0, 0xFF];
matrix = {matrixType:"box", x:0, y:21, w:8, h:6, r:(90/180)*Math.PI};
beginGradientFill("linear", colors, alphas, ratios, matrix);
lineStyle(0,0xFFFFFF,100);
moveTo(-4,18);
curveTo(-4,22,-5.5,25);
lineStyle(0,0x000000,100);
lineTo(5.5,25);
lineStyle(0,0x666666,100);
curveTo(4,22,4,18);
lineStyle(0,0xCCCCCC,100);
lineTo(-4,18);
endFill();
lineStyle(0,0x999999,0);
beginFill(0x333333,100);
moveTo(-4,-1);
lineTo(4,-1);
lineTo(4,1);
lineTo(-4,1);
lineTo(-4,-1);
endFill();
lineStyle(0,0xFFFFFF,100);
moveTo(-4,1);
lineTo(4,1);
lineTo(4,-1);
lineStyle(0,0x999999,100);
moveTo(-4,-18);
lineTo(4,-18);
curveTo(6,0,4,18);
lineTo(-4,18);
curveTo(-6,0,-4,-18);
colors = [0x000000, 0x000000];
alphas = [40, 10];
ratios = [0, 0x66];
matrix = {matrixType:"box", x:0, y:15, w:2, h:60, r:(90/180)*Math.PI};
beginGradientFill("linear", colors, alphas, ratios, matrix);
lineStyle(0,0xFF0000,0);
moveTo(-5.5,25);
lineTo(5.5,25);
lineTo(5.5,-25);
curveTo(8,-20,10,-6);
curveTo(8,-6,8,2);
lineTo(8,30);
curveTo(7,32,6,32);
lineTo(0,32);
curveTo(-6.5,29,-5.5,25);
endFill();
lineStyle(0,0x666666,80);
moveTo(-5.5,25);
lineTo(5.5,25);
lineTo(5.5,-25);
_xscale = 100;
_yscale = 100;
}
}
my_format.align = "center";
my_format.size = 12;
my_format.color = 0x000000;
mypath.createTextField("percentage",mypath.getNextHighestDepth(),-32,24,55,50);
mypath["percentage"].setNewTextFormat(my_format);
mypath["percentage"].selectable = false;
mypath["percentage"].wordWrap = true;
mypath["percentage"].text = "harmonic
percentage";
text1 = "harmonic";
text2 = "order";
text1_y = -100;
text2_y = -80;
my_format.align = "center";
my_format.bold = true;
my_format.color = 0xFFFFFF;
my_format.size = 14;
for(var i = 0; i < text1.length; i++) {
mypath.createTextField("mylabel1" + i,mypath.getNextHighestDepth(),-20,text1_y,14,20);
mypath["mylabel1" + i].setNewTextFormat(my_format);
mypath["mylabel1" + i].selectable = false;
mypath["mylabel1" + i].text = text1.substring(i, i+1);
text1_y += 12;
}
for(var i = 0; i < text1.length; i++) {
mypath.createTextField("mylabel2" + i,mypath.getNextHighestDepth(),-5,text2_y,14,20);
mypath["mylabel2" + i].setNewTextFormat(my_format);
mypath["mylabel2" + i].selectable = false;
mypath["mylabel2" + i].text = text2.substring(i, i+1);
text2_y += 12;
}
}
//function to make a (filled) rectangle based on four input corners and color info
function make_a_rectangle(mypath,linecolor,fillcolor,linealpha,fillalpha,linewidth,left_x,right_x,top_y,bottom_y) {
mypath.lineStyle(linewidth, linecolor, linealpha);
mypath.beginFill(fillcolor,fillalpha);
mypath.moveTo(left_x,top_y);
mypath.lineTo(right_x,top_y);
mypath.lineTo(right_x,bottom_y);
mypath.lineTo(left_x,bottom_y);
mypath.lineTo(left_x,top_y);
mypath.endFill();
}
function displaydelay(mypath){
mypath.solidbox._visible = 1;
mypath.solidbox._alpha = 0;
mypath.fadingbox._visible = 1;
mypath.myhint._visible = 1;
mypath.fadingbox._alpha = 90;
//after the initial delay has elapsed, now make the fade in
fadedelay = setInterval(gradualfade,10,mypath);
clearInterval(initialdelay);
}
function gradualfade(mypath) {
mypath.solidbox._alpha += 4;
mypath.fadingbox._alpha -= 4;
if(mypath.solidbox._alpha >= 100) {
clearInterval(fadedelay);
}
}
function limit_decimals(myinput) {
return_for_display = String(Math.round(myinput*100)/100);
return_for_display = return_for_display.split("").reverse().join("");
//trace(return_for_display.indexOf("."));
if(return_for_display.indexOf(".") <> -1) {
for(var i=2; i> return_for_display.indexOf("."); i--) {
return_for_display = "0" + return_for_display;
}
} else {
return_for_display = "00." + return_for_display;
}
return_for_display = return_for_display.split("").reverse().join("");
return(return_for_display);
}
//create movie clips to fill
//"sinewave" is nested /in "sine" in a previous version that was required but technically is
//no longer. I went ahead and left it this way because it is so easy to reverse the direction
//of the wave travel this way just by setting the _xscale of its parent ("sine")
this.createEmptyMovieClip("oscope",this.getNextHighestDepth());
this.createEmptyMovieClip("sine",this.getNextHighestDepth());
this.sine.createEmptyMovieClip("sinewave",this.sine.getNextHighestDepth());
this.createEmptyMovieClip("sliders",this.getNextHighestDepth());
this.createEmptyMovieClip("harmonicsdata",this.getNextHighestDepth());
this.createEmptyMovieClip("sine_masker",this.getNextHighestDepth());

mylabels = new Array();
topcolor = 0x990000;
bottomcolor = 0xFFCC00;
linecolor = 0xFFFFFF;
leftmargin = 10;
slotcolor = 0x000000;
sliders._x = 10;
sliders._y = 65;
mylabels = ["1st","5th","7th","11th","13th","17th","19th","23rd","25th","29th","31st","35th","37th","41st","43rd","47th","49th"];
//number_of_buttons = mylabels.length;
makeslider(sliders,mylabels.length,topcolor,bottomcolor,linecolor,slotcolor,leftmargin,mylabels);

harmonics = new Array();
//set initial values for the array. In this case, since there are zero harmonics, the result will be a sine wave
harmonics.push ({myorder:1,myamount:1.0,mysuffix:"st"});
harmonics.push ({myorder:5,myamount:0.0,mysuffix:"th"});
harmonics.push ({myorder:7,myamount:0.0,mysuffix:"th"});
harmonics.push ({myorder:11,myamount:0.0,mysuffix:"th"});
harmonics.push ({myorder:13,myamount:0.0,mysuffix:"th"});

Sine Wave Picture Effect
how do i make this sine wave picture effect ,wave on the horizontal insted of the vertical
)
( vertical as it is now
)

//// horizontal as i want it to be
http://www.mn001c7645.pwp.blueyonder.co.uk/test.htm

Sine Wave/blob Effect
Hey everyone,

I have a logo that I made in Fireworks, and it looks decent, but I was wondering if anyone could mimic it with movement. For example, if someone could use actionscript to make it "wiggle" or wave like a flag in the wind, that would be awesome.

Notice how the blue line itself stays at about the same thickness (it barely starts getting thicker), but the shading around it thickens as it goes more and more to the right.

Here's the image (ignore the text):



Thanks for any help / tips
Matt

Sine Wave Picture Effect
how do i make this sine wave picture effect ,wave on the horizontal insted of the vertical
)
( vertical as it is now
)

//// horizontal as i want it to be
http://www.mn001c7645.pwp.blueyonder.co.uk/test.htm

[Flash MX] How To Create A Sine Wave
[Flash MX] How to create a sine wave using the curveto() method of the flash drawing API ??

Need Advice To Create A Sine Wave Dynamically
Is it possible for Flash to draw a line from point A to point B dynamically?

I have to create a sine wave that plots points on the screen. I thought it would be possible to duplicate a movieclip of a dot, and everytime a new position in the sine wave is created, then the movieclip would duplicate and place the dot on the screen at that position. So far, not very hard, but I need a solid line for the sine wave, hence the question, can I draw a line dynamically from point A to point B?

Any help would be much appreciated.

Cheers,

vglcrew

How Do You Rotate A Graphic Using Math Sine Wave
Hi there I hope someone can help me. I want to make a movie clip graphic rotate using its _rotate property. However I want to make it start rotating slowly from a stopped position and increase to a certain speed then slow down again then do the same thing only rotating in the opposite direction. All I know is the 'sine wave' would be used in the calculation. I know nothing about math - the word itself scares me. Ideally I would like to change a number in the equation that would make the back and forth rotation go faster and I would like another number in the equation to govern the frequency of the spin (so I need two parameters amplitude and frequency). I have no idea how to write this equation or how to attach it to my movie clip graphic. Help on this matter would be appreciated.

At present I'm making a movie clip rotate using:

this._rotation=this._rotation+x; (if I change the value of x as you know the rotation would be faster). I would like to keep the new back and forth rotation as close to this way of rotating the clip as possible.

Cheers

Dynamic Text On Sine Curve Path?
Hi,

This is really a kinda urgent requirement, I hate being urgent on forums since help takes as long as it takes usually, but I'm being pressured at the moment and can't do it.

Basically I need to have text from a dynamic/input textfield to appear in a wavy line pattern automatically. Now I'm pretty sure it can be done fairly easily with the right knowledge but I unfortunately lack that knowledge.

The idea I had was that a string is broken into individual letters and each is placed along a sine curve of a set length/width - the string/characters are repeated if necessary in order that the full width of the curve is covered. Also note that the text need not be rotated to match the lines, only _x and _y values need to be adjusted.

I have to produce a design with dynamic text similar to this (my ascii art skills are crap so please imaging that these are wavy lines rather than zig zags):

/////////////////
/////////////////
/////////////////
/////////////////
/////////////////

Please please please, I need your help - desperately, I have nothing to offer apart from the satisfaction of producing a wavy text pattern and from knowing that you have saved me from a breakdown.

Thanks guys,

Jon

Copyright © 2005-08 www.BigResource.com, All rights reserved