Advertisement
999ms

Untitled

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