fork download
  1. var date = new Date;
  2. var drawFlag = false;
  3. var oldX = 0;
  4. var oldY = 0;
  5. window.addEventListener("load", function(){
  6. var can = document.getElementById("myCanvas");
  7. can.addEventListener("mousemove", draw, true);
  8. can.addEventListener("mousedown", function(e){
  9. drawFlag = true;
  10. oldX = e.clientX;
  11. oldY = e.clientY;
  12. }, false);
  13. can.addEventListener("mouseup", function(){
  14. drawFlag = false;
  15. }, false);
  16. }, true);
  17. // 描画処理
  18. function draw(e){
  19. if (!drawFlag) return;
  20. var x = e.clientX;
  21. var y = e.clientY;
  22. var can = document.getElementById("myCanvas");
  23. var context = can.getContext("2d");
  24. var r = Math.floor(Math.random() * 256);
  25. var g = Math.floor(Math.random() * 256);
  26. var b = Math.floor(Math.random() * 256);
  27. context.strokeStyle = "rgba("+ [r,g,b].join(',') + ",255)";
  28. context.lineWidth = 200;
  29. context.beginPath();
  30. context.moveTo(oldX, oldY);
  31. context.lineTo(x, y);
  32. context.stroke();
  33. context.closePath();
  34.  
  35. context.strokeStyle = "rgba(255,0,0,255)";
  36. context.lineWidth = 1;
  37. context.beginPath();
  38. context.moveTo(oldX, oldY);
  39. context.lineTo(x, y);
  40. context.stroke();
  41. context.closePath();
  42. oldX = x;
  43. oldY = y;
  44. console.log(date.toLocaleString() + ' : ' + x + ',' + y);
  45. }
  46.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty