ひさびさCANVAS!
HTML5 canvas について教えてください!
http://oshiete.goo.ne.jp/qa/8207582.html
久々に書く。蛇足を描いてみたいがために。
追記
http://javascripter.hatenablog.com/entry/20080531/1212264942
<!DOCTYPE html> <meta charset="utf-8"> <title>korega CG?</title> <style> canvas { border : 1px red solid; } </style> <body> <h1>LINE</h1> <canvas width="400" height="400" id="hoge"></canvas> <script> function animeLine (a,b,c,d,e,f,g, h) { var ctx = a.getContext('2d'); var x = b, y = c; var sx = (d - b) / f; var sy = (e - c) / f; var ct = f; var mx = a.offsetWidth; var my = a.offsetHeight; (function LOOP () { ctx.beginPath (); if (h) { ctx.moveTo (0, y); ctx.lineTo (x, e); } else { ctx.clearRect (0, 0, mx, my) ctx.moveTo (b, c); ctx.lineTo (x, y); } ctx.closePath (); ctx.stroke (); x += sx; y += sy; if (ct--) setTimeout (LOOP, g); }) (); } function clickHandler (event) { var tgt = event.target; var pos = tgt.getBoundingClientRect(); var psx = (event.pageX - pos.left) / 10 |0; var psy = (event.pageY - pos.top) / 10 |0; if (! (psx + psy)) animeLine (tgt, psx, psy, 400, 400, 50, 20, 1); } document.querySelector ('#hoge'). addEventListener ('click', clickHandler, false); </script>