Hi Roy. It seems like it's been decades since I said hello.

I'm not sure I understand exactly what you're doing, but I gave it a shot.
If you're trying to get a value for motor speed that is between 60 and 255,
here's a way to do it without relying on a fixed distance. This seems goofy,
but it was the first thing that popped into my head.

Determine the value for motor acceleration directly. The problem is, the
easing equations return the final value of the prop in question, so you
can't send motor speed to easeInOutCubic the way you can send distance. That
is, you can't get 60 to 255 to 60. You might be able to switch to Back
instead of Cubic, if you want to simplify things, but I didn't try that.
Instead, I used easeIn and then used the same values in reverse, to simulate
your desired easeInOutCubic.

The only flaw I see in this idea--which may not apply in your situation--is
that it will take a lot longer to finish the sequence over longer distances.
If you use the trapezoidal velocity profile you cited, the motor will run at
max velocity for the longest of any velocity. Using this simulated
easeInOutCubic, it's only at max velocity for one iteration. For short
distances that might be fine, but if you had to travel a long distance, it
would take a lot longer to get there.

This example just traces the actual motor speed. I understood your post to
say that it should be between 60 and 255. However, I used variables so you
could change that if I'm wrong.

//arbitrary distance
var distanceStart:Number = 0;
var distanceFin:Number = 50;
var distanceHalf:Number = (distanceFin - distanceStart) / 2;
var timeIncr:Number = 0;

var minMotorSpeed:Number = 60;
var maxMotorSpeed:Number = 255;
//one simple way to avoid exeeding the max value by the min value is to
//  run the equations starting with zero. Can compensate another way.
var easeStart:Number = 0;
var easeFin:Number = maxMotorSpeed - minMotorSpeed;

var accArray:Array = new Array();

this.onEnterFrame = function() {
    var motorSpeed:Number;
    var motorAcc:Number;
    if (timeIncr <= distanceHalf) {
        motorAcc = easeInCubic(timeIncr, easeStart, easeFin, distanceHalf);
        //store in array, avoiding duplication of last value
        if (timeIncr < distanceHalf) { accArray.push(motorAcc); }
        motorSpeed = minMotorSpeed + motorAcc;
    } else {
        motorSpeed = minMotorSpeed + accArray.pop();
    }
    //the value needed:
    trace(timeIncr + " " + motorSpeed);

    if (timeIncr >= distanceFin) {delete this.onEnterFrame;}
    timeIncr++;
};

function easeInCubic(t:Number, b:Number, c:Number, d:Number):Number {
    return c * (t /= d) * t * t + b;
}


_______________________________________________
[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

Reply via email to