Last active
February 2, 2021 06:36
-
-
Save diska/3797a83dbfdd2de90423a00e7be9d457 to your computer and use it in GitHub Desktop.
とりあえずマルチタッチな小さいコードcanvas2d版。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <canvas width="512" height="512"></canvas><hr/> | |
| <textarea id="LOG" cols="30" rows="10" value=""></textarea> | |
| <script>"use strict"; | |
| let cx=document.querySelector("canvas").getContext("2d"); | |
| cx.canvas.addEventListener("touchstart",hander,false); | |
| cx.canvas.addEventListener("touchmove",hander,false); | |
| function hander(e){ | |
| e.preventDefault(); | |
| let touches=e.changedTouches; | |
| for (let i=0; i<touches.length; i++){ | |
| drawRect(touches[i].pageX,touches[i].pageY, i); | |
| } | |
| } | |
| function drawRect(x,y,num){ | |
| cx.fillStyle=["#f00","#0f0","#00f","#ff0","#0ff","#f0f",][num]; | |
| cx.fillRect(x,y,16,16); LOG.value+=`(${x},${y}),${cx.fillStyle}\n`; | |
| } | |
| </script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment