naimul64

AutoColor

Apr 27th, 2017
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5 1.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4.     <title>Auto Color</title>
  5. </head>
  6. <body id="myBody" style="background-color: #000000">
  7. <h1 style="text-align: center;">
  8.     HELLO     WORLD
  9. </h1>
  10. <img style="float: middle;" src="gif/giphy3.gif">
  11. </body>
  12. <script type="text/javascript">
  13.     var r=0;
  14.     var g=0;
  15.     var b=0;
  16.     rpos = true;
  17.     gpos = true;
  18.     bpos = true;
  19.     window.setInterval(function(){
  20.       changeColor();
  21.     }, 25);
  22.  
  23.     function changeColor() {
  24.         document.getElementById("myBody").style.backgroundColor = "rgb("+r+", "+g+", "+b+")";
  25.        
  26.         if (rpos) {
  27.             r = r + 1;
  28.             if (r > 255){
  29.                 r = r - 1;
  30.                 rpos = false;
  31.             }
  32.         } else {
  33.             r = r - 1;
  34.             if (r < 0) {
  35.                 r = r + 1;
  36.                 rpos = true;
  37.             }
  38.         }
  39.  
  40.         if (gpos) {
  41.             g = g + 2;
  42.             if (g > 255){
  43.                 g = g - 2;
  44.                 gpos = false;
  45.             }
  46.         } else {
  47.             g = g - 2;
  48.             if (g < 0) {
  49.                 g = g + 2;
  50.                 gpos = true;
  51.             }
  52.         }
  53.  
  54.         if (bpos) {
  55.             b = b + 3;
  56.             if (b > 255){
  57.                 b = b - 3;
  58.                 bpos = false;
  59.             }
  60.         } else {
  61.             b = b - 3;
  62.             if (b < 0) {
  63.                 b = b + 3;
  64.                 bpos = true;
  65.             }
  66.         }
  67.     }
  68. </script>
  69. </html>
Add Comment
Please, Sign In to add comment