Skip to content

Instantly share code, notes, and snippets.

@brentp
Created March 25, 2009 05:20
Show Gist options
  • Save brentp/85306 to your computer and use it in GitHub Desktop.
Save brentp/85306 to your computer and use it in GitHub Desktop.
var ctx = $('#canvas')[0].getContext("2d");
var off = jQuery('#canvas').offset();
jQuery._canvas = {'x': off.left, 'y': off.top};
ctx.fillStyle = "rgba(255, 0, 0, 1)";
ctx.beginPath();
ctx.arc(75, 75, 10, 0, Math.PI*2, true);
ctx.closePath();
ctx.stroke();
console.log(ctx.isPointInPath(75, 75));
function arrow(ctx, y, xmin, xmax, style){
ctx.save();
ctx.translate(0, y);
ctx.fillStyle = "rgba(255, 0, 0, 0.7)";
var head_len = 30;
ctx.beginPath();
ctx.moveTo(xmin, 10);
ctx.lineTo(xmin, 60);
ctx.lineTo(xmax - head_len, 60);
ctx.lineTo(xmax - head_len, 70);
ctx.lineTo(xmax, 35);
ctx.lineTo(xmax - head_len, 0);
ctx.lineTo(xmax - head_len, 10);
ctx.closePath();
ctx.stroke();
ctx.fill();
ctx.restore();
}
arrow(ctx, 90, 10, 250);
jQuery('#canvas').unbind('mousemove');
jQuery('#canvas').mousemove(function(e){
var x = e.pageX - jQuery._canvas.x;
var y = e.pageY - jQuery._canvas.y;
if(ctx.isPointInPath(x, y)){
console.log((new Date()).getTime());
console.log(e);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment