Advertisement
999ms

Project.v2

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