I have screen width, screen height(For example 1360 X 768) and image width and height( For example 400 X 400). I want to display every image on random x, y position on the screen and to display an image in that position. Also, rotate the image at random degree.
So, I used following code to find X, Y random position from screen.
var randPosX = Math.floor((Math.random()*(screen_width - image_width )));
var randPosY = Math.floor((Math.random()*(screen_height - image_height )));
so, this will return me X, Y within screen area so that whole image is shown.
Now, I have use rotation code
var rNum = Math.round((Math.random()*360)+1);
Apply on div
$('img').css('left',Math.abs(new_x_point) );
$('img').css('top', Math.abs(new_y_point));
$('img').css('position','absolute');
$('img').css('transform','rotate('+rNum+'deg)');
Now, After rotation, X, Y position changed so sometime it cut the image on the screen.
Also i tried to find new X,Y after rotation and apply it using following logic:
new_x_point = randPosX * Math.cos(rNum) - randPosY * Math.sin(rNum);
new_y_point = randPosY * Math.cos(rNum) + randPosX * Math.sin(rNum);
HTML
<div id="image_0" style="display:none;height:768px;width:1360px;z-index:1;position: absolute"><img src="001.png" style="height:400px;width:400px;" class="product-img"></div>
<div id="image_1" style="display:none;height:768px;width:1360px;z-index:1;position: absolute"><img src="002.png" style="height:400px;width:400px;" class="product-img"></div>
<div id="image_2" style="display:none;height:768px;width:1360px;z-index:1;position: absolute"><img src="003.png" style="height:400px;width:400px;" class="product-img"></div>
etc
But it is not working :(. Please help Thanks