Advertisement
Guest User

Untitled

a guest
Nov 18th, 2019
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. var shapes = document.getElementById("shapes")
  2. var color = 0
  3.  
  4. function randNum(min, max) {
  5. min = Math.ceil(min);
  6. max = Math.floor(max);
  7. return Math.floor(Math.random() * (max - min + 1)) + min; //The maximum is inclusive and the minimum is inclusive
  8. }
  9.  
  10. setInterval(() => {
  11. var shaping = randNum(1, 4)
  12. var top = randNum(10, 80)
  13. var left = randNum(10, 80)
  14. if (shaping === 1) {
  15. // Square
  16. shapes.style.width = "120px"
  17. shapes.style.height = "120px"
  18. shapes.style.borderRadius = "0px"
  19. shapes.style.left = `${left}%`
  20. shapes.style.top = `${top}%`
  21.  
  22. } else if (shaping === 2) {
  23. // Circle
  24. shapes.style.width = "120px"
  25. shapes.style.height = "60px"
  26. shapes.style.borderRadius = "0px"
  27. shapes.style.left = `${left}%`
  28. shapes.style.top = `${top}%`
  29.  
  30.  
  31. } else if (shaping === 3) {
  32. // Circle
  33. shapes.style.width = "100px"
  34. shapes.style.height = "100px"
  35. shapes.style.borderRadius = "100px"
  36. shapes.style.left = `${left}%`
  37. shapes.style.top = `${top}%`
  38.  
  39.  
  40. } else if (shaping === 4) {
  41. //
  42. shapes.style.width = "100px"
  43. shapes.style.height = "100px"
  44. shapes.style.borderRadius = "100px"
  45. shapes.style.left = `${left}%`
  46. shapes.style.top = `${top}%`
  47.  
  48.  
  49. }
  50.  
  51. var color = randNum(1, 4)
  52.  
  53. if (color === 1){
  54. shapes.style.background = "dodgerblue"
  55. }else if (color === 2) {
  56. shapes.style.background = "lightgreen"
  57. }else if (color === 3) {
  58. shapes.style.background = "pink"
  59. }else if (color === 4) {
  60. shapes.style.background = "red"
  61. }
  62. },500)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement