diff --git a/script.js b/script.js index 0eb08b0..d477652 100644 --- a/script.js +++ b/script.js @@ -6,6 +6,10 @@ // ["264653","2a9d8f","e9c46a","f4a261","e76f51"] // https://coolors.co/palette/264653-2a9d8f-e9c46a-f4a261-e76f51 +// +// Firefox seems to have an issue with rendering. Google works fine. +// + const canvas = document.getElementById('canvas1'); const ctx = canvas.getContext('2d'); canvas.width = 1024; @@ -27,15 +31,20 @@ this.blueAvg = 0; this.grayValue = undefined; this.grayScaleArray = []; - this.palette = ["264653","2a9d8f","e9c46a","f4a261","e76f51"]; + // this.palette = ["264653","2a9d8f","e9c46a","f4a261","e76f51"]; + // this.palette = ["780116","f7b538","db7c26","d8572a","c32f27"]; + // this.palette = ["220901","621708","941b0c","bc3908","f6aa1c"]; // prettiest + this.palette = ["172121","444554","7f7b82","bfacb5","e5d0cc"]; // gray scale + this.slideX = 0; + this.slideY = 0; this.image = document.getElementById('projectImage'); } draw(context) { - if (this.grayValue === undefined) { + // if (this.grayValue === undefined) { context.drawImage(this.image, this.x, this.y, this.width, this.height , this.x, this.y, this.width, this.height); - context.strokeRect(this.x, this.y, this.width, this.height); + // context.strokeRect(this.x, this.y, this.width, this.height); // if (this.x === 0 && this.y === 0) { for(let y = this.y; y < this.y + this.height; y++) { @@ -54,16 +63,23 @@ // console.log('Gray value: ' + this.grayValue); // } - } - - if (this.grayValue !== undefined) { - // console.log('Here...'); - // const paletteIndex = Math.floor(this.grayValue / 50); - // console.log('(' + this.x + ', ' + this.y + ') palIndex:' + paletteIndex); - // context.fillStyle = '#' + this.palette[paletteIndex]; - context.fillStyle = "rgb(" + this.redAvg + "," + this.greenAvg + "," + this.blueAvg + ")"; + const paletteIndex = Math.floor(this.grayValue / 50); + // const paletteIndex = this.grayValue % this.palette.length; + console.log('(' + this.x + ', ' + this.y + ') palIndex:' + paletteIndex); + context.fillStyle = '#' + this.palette[paletteIndex]; + // context.fillStyle = "rgb(" + this.redAvg + "," + this.greenAvg + "," + this.blueAvg + ")"; context.fillRect(this.x, this.y, this.width, this.height); - } + // } + + // if (this.grayValue !== undefined) { + // // console.log('Here...'); + // const paletteIndex = Math.floor(this.grayValue / 50); + // // const paletteIndex = this.grayValue % 3; + // console.log('(' + this.x + ', ' + this.y + ') palIndex:' + paletteIndex); + // context.fillStyle = '#' + this.palette[paletteIndex]; + // // context.fillStyle = "rgb(" + this.redAvg + "," + this.greenAvg + "," + this.blueAvg + ")"; + // context.fillRect(this.x, this.y, this.width, this.height); + // } } calculateGrayAmount(red, green, blue) { @@ -78,12 +94,17 @@ this.canvas = canvas; this.width = this.canvas.width; this.height = this.canvas.height; - this.numCols = 64; - this.numRows = 31; + this.numCols = this.canvas.width; + this.numRows = this.canvas.height; + // this.numCols = 64; + // this.numRows = 31; this.cellWidth = this.width / this.numCols; this.cellHeight = this.height / this.numRows; this.imageGrid = []; this.createGrid(); + // this.cell = new Cell(this, 0, 0); + + // console.log(this.imageGrid); } createGrid() { @@ -95,8 +116,9 @@ } render(context) { - - this.imageGrid.forEach(cell => { + // this.cell.draw(context); + this.imageGrid.forEach(cell=> { + // cell.update(); cell.draw(context); }) } @@ -104,15 +126,15 @@ } const effect = new Effect(canvas); -console.log(effect); -effect.render(ctx); +// console.log(effect); +// effect.render(ctx); -// function animate() { -// ctx.clearRect(0, 0, canvas.width, canvas.height); -// requestAnimationFrame(animate); -// } +function animate() { + effect.render(ctx); + // requestAnimationFrame(animate); +} -// animate(); +animate(); /* TODO: