fork download
  1. var can;
  2. var context;
  3. var drawFlag = false;
  4. var oldX = 0;
  5. var oldY = 0;
  6. window.addEventListener("load", function(){
  7. can = document.getElementById("myCanvas");
  8. context = can.getContext("2d");
  9.  
  10. can.addEventListener("mousemove", draw, true);
  11. can.addEventListener("mousedown", function(e){
  12. drawFlag = true;
  13. oldX = e.clientX;
  14. oldY = e.clientY;
  15. context.beginPath();
  16. context.lineWidth = 50;
  17. context.lineJoin = 'round';
  18. context.strokeStyle = "rgba(255,0,0,255)";
  19. context.moveTo(oldX, oldY);
  20. }, false);
  21. can.addEventListener("mouseup", function(){
  22. drawFlag = false;
  23. context.closePath();
  24. }, false);
  25. }, true);
  26. // 描画処理
  27. function draw(e){
  28. if (!drawFlag) return;
  29. var x = e.clientX;
  30. var y = e.clientY;
  31. context.lineTo(x, y);
  32. context.stroke();
  33. }
  34.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty