views:

63

answers:

3

Hi,

I'm trying to understand some flash animation, and am having difficulty working out the following. Can anyone help?

I want to convert a degree range of 0 to 90, to a value between 0 and 1

These is an existing function to convert from the range 0 to 1 to degrees, eg:

function convertToDegrees(Int:Pos)
{
    var rot = (45 * pos);  
    var degrees = (90 - ( rot * 2 ));  

    return degrees;
}

Now to convert backwards, from degrees to 0 to 1 value, I am trying: (WHICH IS WRONG)

function convertFromDegrees(Int:currentDegreeValue )
{
    var rot =  (currentDegreeValue / 2) + 90;  
    var Pos = rot / 45;

    return Pos;  
}

Can anyone help me as to where I am going wrong?

+1  A: 

I want to convert a degree range of 0 to 90, to a value between 0 and 1

How about:

x / 90.0
Pete
Since he accepted the other answer, frank must've meant that he wanted "to convert a degree range of **90 to 0**, to a value between **0 and 1** "
Pete
A: 

rot = (90 - degrees) / 2

Henrik
+2  A: 

The first function could be simplified to 90 * (1 - pos), so the reverse function would be 1 - (degrees / 90).

legoscia
fantastic! Thank you
frank