Skip to content

Instantly share code, notes, and snippets.

@andykent
Created July 4, 2012 16:06
Show Gist options
  • Save andykent/3048069 to your computer and use it in GitHub Desktop.
Save andykent/3048069 to your computer and use it in GitHub Desktop.
Basic Canvas Drawing
// add some interactivity
var canvas = document.querySelector("#canvas"),
ctx = canvas.getContext("2d");
ctx.beginPath();
ctx.lineWidth = 10;
ctx.strokeStyle = 'lime';
ctx.lineCap = 'round';
ctx.lineJoin = 'round';
ctx.moveTo(10,10);
ctx.lineTo(10,100);
ctx.lineTo(100, 100);
ctx.lineTo(100, 10);
ctx.lineTo(10, 10);
ctx.stroke();
function onMouseMove(e)
{
var mouseX = e.clientX;
var mouseY = e.clientY;
ctx.lineTo(mouseX, mouseY);
ctx.stroke();
}
canvas.addEventListener("mousemove", onMouseMove, false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment