Skip to content

Instantly share code, notes, and snippets.

@jameshibbard
Created September 11, 2012 10:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jameshibbard/3697359 to your computer and use it in GitHub Desktop.
Save jameshibbard/3697359 to your computer and use it in GitHub Desktop.
Function to draw a rectangle on a canvas element
function clearCanvas(context, canvas) {
context.clearRect(0, 0, canvas.width, canvas.height);
var w = canvas.width;
canvas.width = 1;
canvas.width = w;
}
function highlightRoom(x, y, h, w){
var can = document.getElementsByTagName('canvas')[0];
var ctx = can.getContext('2d');
clearCanvas(ctx, can);
ctx.strokeStyle = '#f00';
ctx.lineWidth = 5;
ctx.lineJoin = 'round';
ctx.strokeRect(x,y,h,w);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment