(boxWidth, boxHeight)
| 24 | |
| 25 | |
| 26 | function getNewPosition(boxWidth, boxHeight) { |
| 27 | |
| 28 | // The boxWidth and boxHeight are subtracted so that they would not move out from the right and bottom direction |
| 29 | var newX = Math.floor((Math.random() * viewWidth) + 1 - boxWidth); |
| 30 | var newY = Math.floor((Math.random() * viewHeight) + 1 - boxHeight); |
| 31 | |
| 32 | // These will satisfy that box does not move go out in the top and left direction |
| 33 | if(newX < 0) { |
| 34 | newX = 0; |
| 35 | } |
| 36 | if(newY < 0) { |
| 37 | newY = 0; |
| 38 | } |
| 39 | |
| 40 | return {x: newX, y: newY}; |
| 41 | } |