This one was a preliminary for a future project that I will be working on. One of the things that I love about Actionscript is that it's modular. If you notice, each of the Sine and Cosine scripts are placed one on top of the other. All of the trace commands are at the bottom. When you use trace, it only prints the result in the output window in Flash CS5 Professional it won't print in the actual animation. We'll get to that part in a little bit.
function FindSin(Fin:Number):Number {
var Truest1 = Math.sin(Fin);
return Truest1;
}
function Cosin(FinC:Number):Number {
var Truest2 = Math.sin(FinC);
return Truest2;
}
function Cosin2(FinC:Number):Number {
var Truest1 = Math.sin(FinC);
return Truest1;
}
function Tangent(FinT:Number):Number {
var Truest1 = Math.sin(FinT);
return Truest1;
}
trace(FindSin(115));
trace (FindSin(99));
trace (FindSin(999));
trace (Cosin(55));
trace (Cosin(300));
trace (Cosin2(55));
trace (Cosin2(300));
trace (Tangent(211));
trace (Tangent(37));
trace (Tangent(90));
trace (Tangent(123));
trace (Tangent(5));
If you notice, there are two Cosine functions. The reason why I put that there was to test the properties. The first Cosine function has a property named Truest2 and the second, Truest1. I had to test and see if the naming of the property in the second Cosine function was conflicting with the naming of the property in the Sine function at the top, which is also called Truest1. To my great relief, they were kept internal.
Now I'm going to show you some of the errors that I made.
function FindSin(Fin:Number):Number {
var Truest1 = Fin * Math.sin(Fin);
return Truest1;
}
trace(FindSin(115));
When I traced the result, it came out to this number.
108.72506341284858
When I saw this I was like HOORAY! But something seemed wrong because when I went to an online calculator and entered the equation into a scientific calculator it came out to this number: .9454353340247703. I was like "Totally WTF"! But then, after a while of bumbling and fidgeting with the numbers, I divided. 108.75 by the a number slightly higher than 0.95 and came up with a number that was very close to the number 115. The area where I messed up was here:
var Truest1 = Fin * Math.sin(Fin);
When I placed Fin in the parenthesis at the right of Math.sin, I bad absolutely no idea that Math.sin was going to multiply itself by Fin AGAIN. I thought that this was just an Aristocratic do-nothing convention, but it turned out to be FUNCTIONAL! So there you have it; I multiplied Math.sin by Fin TWICE.
No comments:
Post a Comment