Merge pull request #19 from ljos/colours

Made it possible to change colour.
This commit is contained in:
Jerome Etienne 2012-03-27 01:59:34 -07:00
commit 3e8586d948

View file

@ -12,7 +12,9 @@
width : 256, width : 256,
height : 256, height : 256,
typeNumber : -1, typeNumber : -1,
correctLevel : QRErrorCorrectLevel.H correctLevel : QRErrorCorrectLevel.H,
background : "#ffffff",
foreground : "#000000"
}, options); }, options);
var createCanvas = function(){ var createCanvas = function(){
@ -34,7 +36,7 @@
// draw in the canvas // draw in the canvas
for( var row = 0; row < qrcode.getModuleCount(); row++ ){ for( var row = 0; row < qrcode.getModuleCount(); row++ ){
for( var col = 0; col < qrcode.getModuleCount(); col++ ){ for( var col = 0; col < qrcode.getModuleCount(); col++ ){
ctx.fillStyle = qrcode.isDark(row, col) ? "#000000" : "#ffffff"; ctx.fillStyle = qrcode.isDark(row, col) ? options.foreground : options.background;
ctx.fillRect( col*tileW, row*tileH, tileW, tileH ); ctx.fillRect( col*tileW, row*tileH, tileW, tileH );
} }
} }
@ -55,7 +57,7 @@
.css("height", options.height+"px") .css("height", options.height+"px")
.css("border", "0px") .css("border", "0px")
.css("border-collapse", "collapse") .css("border-collapse", "collapse")
.css('background-color', "#ffffff"); .css('background-color', options.background);
// compute tileS percentage // compute tileS percentage
var tileW = options.width / qrcode.getModuleCount(); var tileW = options.width / qrcode.getModuleCount();
@ -68,7 +70,7 @@
for(var col = 0; col < qrcode.getModuleCount(); col++ ){ for(var col = 0; col < qrcode.getModuleCount(); col++ ){
$('<td></td>') $('<td></td>')
.css('width', tileW+"px") .css('width', tileW+"px")
.css('background-color', qrcode.isDark(row, col) ? "#000000" : "#ffffff") .css('background-color', qrcode.isDark(row, col) ? options.foreground : options.background)
.appendTo($row); .appendTo($row);
} }
} }