Skip to content

Commit

Permalink
Support RGBa
Browse files Browse the repository at this point in the history
  • Loading branch information
khchen428 committed Sep 30, 2012
1 parent f19cde4 commit b623924
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,9 +109,9 @@ or:
adaptToElementSize: true, // defaults to false
depthMap: "01\n10", // defaults to '0' (blank)
numColors: 5, // defaults to 10
palette: [ [255, 0, 0], // set pixel colors
[0, 255, 0], // 2-d array of RGB vals
[0, 0, 255] ] // generated randomly by default
palette: [ [255, 0, 0, 125], // set pixel colors
[0, 255, 0, 255], // 2-d array of RGBa vals
[0, 0, 255, 125] ] // generated randomly by default
});


Expand Down
10 changes: 5 additions & 5 deletions magiceye.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ function MagicEye(opts) {
function randomRGB() {
return [Math.floor(Math.random() * 256),
Math.floor(Math.random() * 256),
Math.floor(Math.random() * 256)];
Math.floor(Math.random() * 256),
255];
}

function generatePalette(numColors) {
Expand Down Expand Up @@ -256,10 +257,9 @@ function MagicEye(opts) {
for (x = 0; x < this.width; x++) {
rgb = this.palette[this.pixels[y][x]];
xOffset = x * 4;
imageData.data[yOffset + xOffset] = rgb[0];
imageData.data[yOffset + xOffset + 1] = rgb[1];
imageData.data[yOffset + xOffset + 2] = rgb[2];
imageData.data[yOffset + xOffset + 3] = 255;
for (i = 0; i < 4; i++) {
imageData.data[yOffset + xOffset + i] = rgb[i];
}
}
}
context.putImageData(imageData, 0, 0);
Expand Down

0 comments on commit b623924

Please sign in to comment.