Advertisement
Guest User

Untitled

a guest
Jul 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /**** DECLARATION ****/
  2. var t=0;
  3.  
  4. /**** RANDOM SHAPES GENERATOR ****/
  5. function randomPos() {
  6.   x = Math.floor(Math.random() * 1000);
  7.   while ((x >= 200) || (x <= 150)) {
  8.       x = Math.floor(Math.random() * 1000);
  9.   };
  10.   y = Math.floor(Math.random() * 1000);
  11.   while ((y >= 200) || (y <= 150)) {
  12.       y = Math.floor(Math.random() * 1000);
  13.   };
  14.   ml = Math.floor(Math.random() * 1000);
  15.   while (ml >= 1000) {
  16.       ml = Math.floor(Math.random() * 1000);
  17.   };
  18.   mt = Math.floor(Math.random() * 1000);
  19.   while (mt >= 200) {
  20.       mt = Math.floor(Math.random() * 1000);
  21.   };
  22.   color = '#'+Math.floor(Math.random()*16777215).toString(16);
  23.   rad = Math.floor(Math.random() * 101);
  24.   if (rad <= 50){
  25.       document.getElementById('shape').style.borderRadius = "100%";
  26.   } else {
  27.       document.getElementById("shape").style.borderRadius = "0%";
  28.   };
  29.   document.getElementById('shape').style.width = x+"px";
  30.   document.getElementById('shape').style.height = y+"px";
  31.   document.getElementById('shape').style.marginLeft = ml+"px";
  32.   document.getElementById('shape').style.marginTop = mt+"px";
  33.   document.getElementById('shape').style.backgroundColor = color;
  34.   document.getElementById('shape').style.display = "block";
  35. };
  36.  
  37. /**** TIMING FUNCTIONALITY ****/
  38. function displayTime() {
  39.   clearInterval(myVar);
  40.   document.getElementById('timeP').innerHTML = 'Your time: ' + s + "s";
  41.   document.getElementById('shape').style.display = "none";
  42.   rt = Math.random() * 1000;
  43.   setTimeout(both, rt);
  44. };
  45. function both() {
  46.   resetPeriod();
  47.   randomPos();
  48. }
  49. function resetPeriod() {
  50.   t=0;
  51.   myVar = setInterval(myTimer, 100);
  52. };
  53. function myTimer() {
  54.   t+=100;
  55.   s = t/1000;s
  56. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement