# Robert Penner Easing Equations

**URL:** <https://forum.kirupa.com/t/robert-penner-easing-equations/21250>\
**Category:** flash\
**Created:** [May 19, 2003, 4:35pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250 "2003-05-19T16:35:17Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![Obelisk](https://avatars.discourse-cdn.com/v4/letter/o/f475e1/32.png) [@Obelisk](https://forum.kirupa.com/u/Obelisk)\
**Post date:** [May 19, 2003, 4:35pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/1 "2003-05-19T16:35:17Z")

</div>

Ok, again I amn sure this is an easy question. But looking at the function below, how would I apply it to an MC to move its position.

// simple linear tweening - no easing  
// t: current time, b: beginning value, c: change in value, d: duration  
Math.linearTween = function (t, b, c, d) {  
return c\*t/d + b;  
};

I need a sample movie file.

Thanks in advanced for the help!

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 5:52pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/2 "2003-05-19T17:52:21Z")

</div>

Anyone have any ideas, suggestions or tutorials?

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 6:39pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/3 "2003-05-19T18:39:52Z")

</div>

If you are new to easing I recommend you check out the basic easing equations. There are 2 tutorials on this site that use them and they are usually all you need for easing.

Robert Penners equations although fun to mess with and are very good, they are very advanced as well.

The way to get the linear tween equation to work is to put these actions on your movie clip…

[AS]onClipEvent (load) {  
var start = this.\_x;  
var end = this.\_x+\_root.endNum;  
var duration = \_root.dNum;  
var t = \_root.tNum;  
}  
onClipEvent (enterFrame) {  
t++;  
if (t\<=duration) {  
this.\_x = Math.linearTween(t, start, end, duration);  
}  
}[/AS]

And put these actions on a frame…

[AS]dNum = 20;  
tNum = 0;  
endNum = 100;  
Math.linearTween = function(t, b, c, d) {  
return c\*t/d+b;  
};[/AS]

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 7:07pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/4 "2003-05-19T19:07:00Z")

</div>

For easier usage, you could easily turn the whole thing into a method. 😉

```auto
MovieClip.prototype.linearTween = function(endx, endy, duration) {
var x = (endx-this._x)/duration, y = (endy-this._y)/duration, t = 0;
this.onEnterFrame = function() {
if (t++<duration) {
this._x += x;
this._y += y;
} else {
delete this.onEnterFrame;
}
};
};

```

Then if you want to move the instance myMovieClip to x:100, y:80, during 24 frames…

```auto
myMovieClip.linearTween(100, 80, 24);

```

…Got it? =)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 7:09pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/5 "2003-05-19T19:09:28Z")

</div>

dang you guys are good… Again thanks for answering my questions.

If you are curious I am currently working on a remoting app in Flash. Needed to easing for my menu. Once it is live, I will definately post a link here.

Again thanks for the help kax and lostInBeta

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 7:16pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/6 "2003-05-19T19:16:22Z")

</div>

You’re welcome. 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 9:54pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/7 "2003-05-19T21:54:39Z")

</div>

kax: Thanks for that. I was thinking about doing that but considering I had to go soon I didn’t have time to go about figuring out and testing it. You rock 😉 :A+:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 10:58pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/8 "2003-05-19T22:58:56Z")

</div>

No need to thank me. =)

And…

> _Originally posted by lostinbeta_  
> **… You rock 😉 :A+:**

I already knew that… 😛 JK 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 19, 2003, 11:10pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/9 "2003-05-19T23:10:11Z")

</div>

hehe. Modest too 😉 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 12:30am UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/10 "2003-05-20T00:30:31Z")

</div>

Yup… I knew that too. :sigh: 😛

Will you ever tell me something that I didn’t know already? 😉

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 2:17am UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/11 "2003-05-20T02:17:01Z")

</div>

I don’t know if I can tell you something you didn’t know already. It would be easy for you to lie and say you already knew 😉 (this is the 8th time this wink smiley has been used in this thread, I love that smiley)

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 2:29am UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/12 "2003-05-20T02:29:22Z")

</div>

Hmmm… that’s a good point. 😛 😉 (I love that smiley too!!)

I guess you have no choice but to trust me… 😛

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 2:33am UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/13 "2003-05-20T02:33:35Z")

</div>

LOL… I love the tongue smiley too 😛 😉

Wow… we definitely overuse those two smilies :!:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 2:46am UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/14 "2003-05-20T02:46:20Z")

</div>

…Who cares!? 😛  
If the smiley is cool, then use it!! 😉 😛

I also like these: :-\ =) 😏 :sleep: :beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [May 20, 2003, 2:56am UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/15 "2003-05-20T02:56:22Z")

</div>

LOL ME TOO!!!

::sensing we are way way way off subject now::

Alright I think we should stop thread hijacking :-\ 😉 😛 :beam:

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [November 11, 2003, 6:51pm UTC](https://forum.kirupa.com/t/robert-penner-easing-equations/21250/16 "2003-11-11T18:51:33Z")

</div>

Well, i did a search for penner easing equations, found this, and found out that there is an error in the code, you forgot to pass the t variable kode. heh. so here it is corrected.

```auto

MovieClip.prototype.linearTween = function(t, endx, endy, duration) {
        var x = (endx-this._x)/duration, y = (endy-this._y)/duration, t;
        this.onEnterFrame = function() {
                if (t++<duration) {
                        this._x += x;
                        this._y += y;
                } else {
                        delete this.onEnterFrame;
                }
        };
};

```

and to call

```auto

myMovieClip.linearTween(0,200, 200, 24);

```

I should note that I’m at school and am using a trial version of mx2004, so maybe in MX you don’t have to pass t for it to work… but meh, incase anyone was having a problem.
