Skip to content

Instantly share code, notes, and snippets.

@davidsonfellipe
Created April 25, 2013 05:50
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 davidsonfellipe/5457768 to your computer and use it in GitHub Desktop.
Save davidsonfellipe/5457768 to your computer and use it in GitHub Desktop.
var Canvas = function(canvas){
this.canvas = canvas;
this.ctx = canvas.getContext('2d');
this.imageData = this.ctx.getImageData(0, 0, canvas.width, canvas.height);
this.data = this.imageData.data;
};
Canvas.prototype.draw = function(color) {
for (var y = 0; y < this.canvas.height; ++y) {
for (var x = 0; x < this.canvas.width; ++x) {
var index = (y * this.canvas.width + x) * 4;
this.data[index] = color.R; // red
this.data[++index] = color.G; // green
this.data[++index] = color.B; // blue
this.data[++index] = 255; // alpha
}
}
this.ctx.putImageData(this.imageData, 0, 0);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment