Advertisement
999ms

Untitled

Dec 12th, 2018
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.62 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>COLORS</title>
  5. <style>
  6.     canvas {background: black }
  7. </style>
  8.  
  9. <script>
  10.   var canvas;
  11.   var ctx;
  12.   const H = 1000;
  13.   const W = 1200;
  14.   var goPath = false;
  15.   var lastAct = 0;
  16.   var list = [];
  17.   var need =  true;
  18.   function init() {
  19.     canvas = document.getElementById('myCanvas');
  20.     ctx = canvas.getContext('2d');
  21.   }
  22.   function printRoungInCenterWithR(x,y,r, clr){
  23.     ctx = canvas.getContext('2d');
  24.     ctx.fillStyle = clr;
  25.     ctx.beginPath();
  26.     var leftAngle = 0;
  27.     var rightAngle = Math.PI*2;
  28.     ctx.arc(x,y,r,leftAngle,rightAngle,false);
  29.     ctx.fill();
  30.   }
  31.  
  32.   var timerId = setInterval(function() {upd();}, 1000/60);
  33.  
  34.  
  35.   function upd(){
  36.     for(var i =0;i<60;i++){
  37.      printRound();
  38.    }
  39.  }
  40.  function printRound(){
  41.    var curTime = getTimeMs();
  42.    if(list.length>0){
  43.       var v = list.pop();
  44.       if(v[4]<curTime){
  45.        printRoungInCenterWithR(v[0],v[1],v[2],v[3]);
  46.      }
  47.      else{
  48.        list.push(v);
  49.      }
  50.    }
  51.  }
  52.  
  53.  onmousemove = function (event) {
  54.    if(getTimeMs()-lastAct<10||!need) return;
  55.    lastAct =getTimeMs();
  56.    var cx = event.pageX-8.5;
  57.    var cy = event.pageY-10;
  58.    var size = 20*Math.random();
  59.    list.push([cx,cy,size, getRandomColor(), lastAct]);
  60.    list.push([cx,cy,size+1, "#000000", lastAct+500]);
  61.    list.sort((a,b)=>-a[4]+b[4]);
  62.   }
  63.   onmousedown = function(event){
  64.     var cx = event.pageX-8.5;
  65.     var cy = event.pageY-10;
  66.     var curR = 15;
  67.     var curTime = getTimeMs();
  68.     var clrArr = new Array(4);
  69.     for(var i=0;i<4;i++)
  70.      clrArr[i] = getRandomColor();
  71.  
  72.    for(var i=0;i<150;i++)
  73.    {
  74.      var len = 3*i;
  75.        list.push([cx+len*Math.cos(i*10),cy+len*Math.sin(i*10),curR-i/10, clrArr[i%4], curTime + 5*i]);
  76.      list.push([cx+len*Math.cos(i*10),cy+len*Math.sin(i*10),(curR+1)-i/10, '#000000', curTime +5*i+1000]);
  77.    }
  78.    list.sort((a,b)=>b[4]-a[4]);
  79.   }
  80.  
  81.   function getTimeMs() {
  82.     var date = new Date();
  83.     return date.getMilliseconds()+date.getSeconds()*1000+date.getMinutes()*1000*60+date.getHours()*60*60*1000;
  84.   }
  85.  
  86.   onkeydown = function(e) {
  87.     var key = e.keyCode;
  88.     if(key==32)need = !need;
  89.   };
  90.  
  91.   function drawImg(img, x,y){
  92.     img.onload =
  93.     function(){
  94.       ctx.drawImage(img, x, y);
  95.     }
  96.   }
  97.  
  98.   function getRandomColor() {
  99.     var letters = '0123456789ABCDEF';
  100.     var color = '#';
  101.     for (var i = 0; i < 6; i++)
  102.    color += letters[Math.floor(Math.random() * 16)];
  103.    return color;
  104.  }
  105.  
  106. </script>
  107. </head>
  108. <body onload = "init()">
  109.   <canvas id="myCanvas" width="1200" height="1000">
  110.   </canvas>
  111. </body>
  112. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement