Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 1.0 (and below)

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-29-2004, 04:27 AM   #1
thaumaturgy
Macromedia Mercenary
 
thaumaturgy's Avatar
 
Join Date: Feb 2004
Location: Rose Bowl Country
Posts: 300
Send a message via Yahoo to thaumaturgy
Default R.Penner's easing formula(s) & mc.lineTo() --> weird results

The sample SWF:

http://rwocreative.com/lineTest/line01.html

The FLA:

http://rwocreative.com/lineTest/line01.fla

Code for frame 1:

PHP Code:
///////////// QUADRATIC EASING ////////////////////////
//// Robert Penner - Sept. 2001 - robertpenner.com ////

// quadratic easing in - accelerating from zero velocity
// t: current time, b: beginning value, c: change in value, d: duration
// t and d can be frames or seconds/milliseconds
Math.easeInQuad = function (tbcd) {
    return 
c*t*t/(d*d) + b;

Code for frame 2:

PHP Code:
stop();

//var coord = [[100,0],[100,100],[0,100],[0,0]]; //This one works with the old method of easing.
var coord = [[100,0],[0,100],[-100,0],[0,-100]]; //This array *sort of* works with RPenner's method.

var 0;
var 
=0;
var 
time 0;
var 
endtime 13;
var 
my_x;
var 
my_y;
var 
oldx 0;
var 
oldy 0;

blank_mc.onEnterFrame = function() {
    
myColorObj.fadeHex(0xFF00001500);
    
this.lineStyle(30x0000FF100);
    if(
coord.length) {
        if(
time endtime) {
            
this.lineTo(my_xmy_y);
            
//my_x -= (my_x - coord[i][0])/2;
            //my_y -= (my_y - coord[i][1])/2;
            //Math.easeInQuad = function (t, b, c, d) {
            //return c*t*t/(d*d) + b; }
            
my_x Math.easeInQuad(timeoldxcoord[i][0], endtime);
            
my_y Math.easeInQuad(timeoldycoord[i][1], endtime);
            
time++;
        } else {
            
time 0;
            
//my_x = coord[i][0];
            //my_y = coord[i][1];
            
oldx coord[i][0];
            
oldy coord[i][1];
            
i++;
        }
    } else {
    
this.onEnterFrame null;
    }    

The Problem:

I'm running into a problem where if I implement Robert Penner's Easing formula to a series of drawn lines (using the Drawing API in MX) it produces funky results. If I just use normal easing techniques (i.e., myX -= ((myX - oldX)/5);) and uncomment the appropriate line in the first else() statement, it works like it should. I'd really REALLY like to implement RPenner's method of easing, but if it doesn't translate well to lines drawn on-the-fly, then I'll have to resort to the tried and true.

Thanks in advance...
thaumaturgy is offline   Reply With Quote
Old 02-29-2004, 12:47 PM   #2
pixelwit
village halfwit
 
pixelwit's Avatar
 
Join Date: Jul 2001
Location: USA, PA
Posts: 3,225
Default

The third argument "c" in the easing function should represent the "Change" from the start value to the end value, not the end value.
Code:
my_x = Math.easeInQuad(time, oldx, coord[i][0]-oldx, endtime);
Or you could change the easing function:
Code:
Math.easeInQuad = function(t, b, c, d) {
	return (c-b)*t*t/(d*d)+b;
};
You should also declare your easing function outside your enterFrame function since there's no need to define the easing equation 24 times per second.

-PiXELWiT
http://www.pixelwit.com
__________________
There are no answers, only choices.
pixelwit is offline   Reply With Quote
Old 02-29-2004, 05:22 PM   #3
thaumaturgy
Macromedia Mercenary
 
thaumaturgy's Avatar
 
Join Date: Feb 2004
Location: Rose Bowl Country
Posts: 300
Send a message via Yahoo to thaumaturgy
Default

Quote:
Originally posted by pixelwit
The third argument "c" in the easing function should represent the "Change" from the start value to the end value, not the end value.
Code:
my_x = Math.easeInQuad(time, oldx, coord[i][0]-oldx, endtime);
Or you could change the easing function:
Code:
Math.easeInQuad = function(t, b, c, d) {
	return (c-b)*t*t/(d*d)+b;
};
You should also declare your easing function outside your enterFrame function since there's no need to define the easing equation 24 times per second.

-PiXELWiT
http://www.pixelwit.com
Dope, thank you Mr. WiT. I didn't declare my function inside my onEnterFrame(), I just put that there (commented out) to remind me what variables goes where and whatnot-who-what-who.
thaumaturgy is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump


All times are GMT. The time now is 07:51 PM.


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2010 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.