hi all,
I am trying to achieve circular motion but my mathematics is really rusty and wrong. i do the animation by creating the path first. here is the code but the path coordinates seem wrong.
---------------------------
I am trying to achieve circular motion but my mathematics is really rusty and wrong. i do the animation by creating the path first. here is the code but the path coordinates seem wrong.
Code:
<html>
<head>
<script language='javascript'>
PreloadImg = function (name)
{
var img = new Image();
img.src = name;
return img;
}
var img_1 = PreloadImg('[URL unfurl="true"]http://www.adelaideunited.com.au/images/ball%20l.jpg');[/URL]
CreateImg = function (_parent,src)
{
var img = document.createElement('IMG');
var wid = parseInt(bdy.clientWidth);
img.src = src;
img.style.position = 'absolute';
img.style.left = '600px';
img.style.top = '100px';
img.style.width = '20px';
img.style.height = '20px';
_parent.appendChild(img);
return img;
}
var _Path_X = new Array(360);
var _Path_Y = new Array(360);
CreatePath = function (orgX,orgY)
{
var x = parseInt(Floater.style.left);
var y = parseInt(Floater.style.top );
var Hyp = Math.sqrt(Math.pow((orgX-x),2)+Math.pow((orgY-y),2));
var stAngle = Math.floor(Math.atan((orgY-y)/(orgX-x))*(180/Math.PI))-1;
for (var n=0;n<=360;n++)
{
stAngle++;
_Path_X[n]=x-(Math.cos((stAngle)*(Math.PI/180))*Hyp);
_Path_Y[n]=y+(Math.sin((stAngle)*(Math.PI/180))*Hyp);
}
}
</script>
</head>
<body onmousedown='MoveImg()'>
<script language='javascript'>
var bdy = document.getElementsByTagName('BODY')[0];
Floater = CreateImg(bdy,img_1.src);
var _Jump = 2;
var IntVal = 100;
var Timer_Id = 0;
var wid = parseInt(bdy.clientWidth)-140;
var x = parseInt(Floater.style.left);
CreatePath(100,100);
var dt = -1;
MoveImg = function ()
{
dt++;
if (dt<=360)
{
Floater.style.left = _Path_X[dt];
Floater.style.top = _Path_Y[dt];
setTimeout(MoveImg,IntVal);
}
}
</script>
</body>
</html>
---------------------------