Jump to content

understand script


atitthaker

Recommended Posts

I came across a script and I am unable understand behaviour of the script.

Here is the script:

//The wakky script that move images...



javascript:
R=0;
x1=.1;
y1=.05;
x2=.25;
y2=.24;
x3=1.6;
y3=.24;
x4=300;
y4=200;
x5=300;
y5=200;
DI=document.images; //return all the images on the page...in array so DI is array now
DIL=DI.length; //get length of DI array so it can be used for getting all images one by one in the loop below
function A()
{
for(i=0; i<DIL; i++)
{
DIS=DI[ i ].style; //get style of each image and store in DIS
DIS.position='absolute';
DIS.left=Math.sin(R*x1+i*x2+x3)*x4+x5; //change position of every image after interval of 5ms
DIS.top=Math.cos(R*y1+i*y2+y3)*y4+y5
}
R++ //change R which is used in setting the position so that with each function call each image will have new position.
}
setInterval('A()',5); //setInterval calls given function reference or expression at each interval spec in ms.
void(0) //just to indicate that function is not returning anything.


//The spead of changing position changes with each stroke of "Go". This is a puzzle for me right now.


Now what it does is, it takes all the images from ur document and rotates it like a marry-go-round or something. All u need to do for it is u just copy whole script in one line and paste in the address bar and it starts working.

Got it?

Now when u click the "Go" button in the browser every time its speed is increasing.with each click it gets faster.

The code I have understood, I have written comment for, but this thing I am unable to understand.


I know this script is of no use except having fun, but still I wanna understand the behaviour, just for knowledge.

If anybody have some spare time than please help me.


Thanks.
Link to comment
https://forums.phpfreaks.com/topic/19862-understand-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.