# Need Code Explanation

**URL:** https://forum.kirupa.com/t/need-code-explanation/122636
**Category:** Uncategorized
**Created:** [September 15, 2004, 4:06pm UTC](https://forum.kirupa.com/t/need-code-explanation/122636 "2004-09-15T16:06:05Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![boolsu](https://avatars.discourse-cdn.com/v4/letter/b/85f322/32.png) [@boolsu](https://forum.kirupa.com/u/boolsu)
#### Post date: [September 15, 2004, 4:06pm UTC](https://forum.kirupa.com/t/need-code-explanation/122636/1 "2004-09-15T16:06:05Z")

</div>

Hello friends…  
Bale here…  
I am a new member to this Group…  
I need the explanation for the following code which is taken from our site

[http://www.kirupa.com/developer/mx/random\_motionMX.htm](http://www.kirupa.com/developer/mx/random_motionMX.htm)

anyway i ll paste the code too here…

Waiting for someone’s response…  
thank you…  
YOurs friendly  
Bala…

function getdistance(x, y, x1, y1) {  
var run, rise;  
run = x1-x;  
rise = y1-y;  
return (\_root.hyp(run, rise));  
}  
function hyp(a, b) {  
return (Math.sqrt(a_a+b_b));  
}  
MovieClip.prototype.reset = function() {  
//specify the width and height of the movie  
width = 300;  
height = 200;  
//-------------------  
var dist, norm;  
this.x = this.\_x;  
this.y = this.\_y;  
this.speed = Math.random()\*4+2;  
this.targx = Math.random()\*width;  
this.targy = Math.random()\*height;  
dist = \_root.getdistance(this.x, this.y, this.targx, this.targy);  
norm = this.speed/dist;  
this.diffx = (this.targx-this.x)\*norm;  
this.diffy = (this.targy-this.y)\*norm;  
};  
MovieClip.prototype.move = function() {  
if (\_root.getdistance(this.x, this.y, this.targx, this.targy)\>this.speed) {  
this.x += this.diffx;  
this.y += this.diffy;  
} else {  
this.x = this.targx;  
this.y = this.targy;  
if (!this.t) {  
this.t = getTimer();  
}  
if (getTimer()-this.t\>1000) {  
this.reset();  
this.t = 0;  
}  
}  
this.\_x = this.x;  
this.\_y = this.y;  
};
