diff --git a/3/assets/image2.jpg b/3/assets/image2.jpg new file mode 100644 index 0000000..ab7c69e Binary files /dev/null and b/3/assets/image2.jpg differ diff --git a/3/assets/image3.jpg b/3/assets/image3.jpg new file mode 100644 index 0000000..13a7e6e Binary files /dev/null and b/3/assets/image3.jpg differ diff --git a/3/assets/image4.jpg b/3/assets/image4.jpg new file mode 100644 index 0000000..d8171f8 Binary files /dev/null and b/3/assets/image4.jpg differ diff --git a/3/index.html b/3/index.html index 34c9dee..a57c71a 100644 --- a/3/index.html +++ b/3/index.html @@ -10,8 +10,8 @@
- - + + diff --git a/3/sketch.js b/3/sketch.js index acd0051..762f8ae 100644 --- a/3/sketch.js +++ b/3/sketch.js @@ -1,8 +1,8 @@ const filterSketch = function (p) { let img; p.setup = function () { - const filterSketch = p.createCanvas(p.windowWidth, p.windowHeight); - filterSketch.parent("filterSketch"); + const sketch = p.createCanvas(p.windowWidth / 4, p.windowHeight / 4); + sketch.parent("filterSketch"); }; p.preload = function () { @@ -12,7 +12,7 @@ const filterSketch = function (p) { p.draw = function () { img.loadPixels(); - p.image(img, 0, 0, 400, 400); + p.image(img, 0, 0, p.windowHeight / 4, p.windowHeight / 4); for (let px = 0; px < img.pixels.length; px += 4) { img.pixels[px] += 50; } @@ -20,51 +20,104 @@ const filterSketch = function (p) { }; }; -const sortSketch = function (p) { +// const sortSketch = function (p) { +// let img; +// p.setup = function () { +// const sortSketch = p.createCanvas(p.windowWidth / 4, p.windowHeight / 4); +// sortSketch.parent("sortSketch"); +// }; +// +// p.preload = function () { +// img = p.loadImage("assets/image2.jpg"); +// p.pixelDensity(1); +// }; +// +// p.draw = function () { +// img.loadPixels(); +// p.image(img, 0, 0, 1920, 1080); +// +// let pixelArray = []; +// for (let px = 0; px < img.pixels.length; px += 4) { +// pixelArray.push([ +// img.pixels[px], +// img.pixels[px + 1], +// img.pixels[px + 2], +// img.pixels[px + 3], +// ]); +// } +// +// pixelArray.sort((a, b) => a[0] - b[0]); +// +// for (let px = 0; px < img.pixels.length; px += 4) { +// img.pixels[px] = (pixelArray[px / 4][0] * 9 + img.pixels[px]) / 10; +// img.pixels[px + 1] = (pixelArray[px / 4][1] * 9 + img.pixels[px + 1]) / 10; +// img.pixels[px + 2] = (pixelArray[px / 4][2] * 9 + img.pixels[px + 2]) / 10; +// img.pixels[px + 3] = (pixelArray[px / 4][3] * 9 + img.pixels[px + 3]) / 10; +// } +// +// console.log(img.pixels); +// img.updatePixels(); +// img.filter(p.BLUR, 100); +// p.image(img, 0, 0, 1920, 1080); +// p.noLoop(); +// }; +// }; + +const resizeSketch = function (p) { let img; p.setup = function () { - const sortSketch = p.createCanvas(p.windowWidth, p.windowHeight); - sortSketch.parent("sortSketch"); + const sketch = p.createCanvas(p.windowWidth / 4, p.windowHeight / 4); + sketch.parent("resizeSketch"); }; p.preload = function () { - // img = p.loadImage("assets/image.png"); - img = p.createImage(66, 66) + img = p.loadImage("assets/image.png"); p.pixelDensity(1); }; p.draw = function () { - img.loadPixels(); - p.image(img, 0, 0, 400, 400); - let pixelArray = []; - for (let px = 0; px < img.pixels.length; px += 4) { - pixelArray.push([ - img.pixels[px], - img.pixels[px + 1], - img.pixels[px + 2], - img.pixels[px + 3], - ]); - } - - pixelArray.sort((a, b) => a[0] - b[0]); - for (let px = 0; px < img.pixels.length; px += 4) { - img.pixels[px] = pixelArray[px / 4][0]; - img.pixels[px + 1] = pixelArray[px / 4][1]; - img.pixels[px + 2] = pixelArray[px / 4][2]; - img.pixels[px + 3] = pixelArray[px / 4][3]; - } - console.log(img.pixels); - for (let x = 0; x < img.width; x += 1) { - for (let y = 0; y < img.height; y += 1) { - img.set(x, y, 0); - } - } - console.log(img.pixels) - p.updatePixels(); - p.image(img, 0, 0, 400, 400); - p.noLoop(); + p.background(255); + p.image(img, 0, 0, p.mouseX / 8, p.mouseX / 8); }; }; + +const evenOddPixelSketch = function (p) { + let img; + let img2; + let finImg; + p.setup = function () { + const sketch = p.createCanvas(p.windowWidth / 2, p.windowHeight / 2); + sketch.parent("evenOddPixelSketch"); + }; + p.preload = function () { + img = p.loadImage("assets/image3.jpg"); + img2 = p.loadImage("assets/image4.jpg"); + finImg = p.createImage(3840, 2160); + p.pixelDensity(1); + }; + p.draw = function () { + img.loadPixels(); + img2.loadPixels(); + finImg.loadPixels(); + for (let i = 0; i < img.pixels.length; i += 4) { + if (i % 8 == 0) { + finImg.pixels[i] = img.pixels[i]; + finImg.pixels[i + 1] = img.pixels[i + 1]; + finImg.pixels[i + 2] = img.pixels[i + 2]; + finImg.pixels[i + 3] = img.pixels[i + 3]; + } else { + finImg.pixels[i] = img2.pixels[i]; + finImg.pixels[i + 1] = img2.pixels[i + 1]; + finImg.pixels[i + 2] = img2.pixels[i + 2]; + finImg.pixels[i + 3] = img2.pixels[i + 3]; + } + } + finImg.updatePixels(); + p.image(finImg, 0, 0, p.windowWidth / 2, p.windowHeight / 2); + noLoop(); + }; +}; + //let test = function (p) { // let img // @@ -98,4 +151,6 @@ const sortSketch = function (p) { //} p5Filter = new p5(filterSketch); -p5Filter = new p5(sortSketch); +// p5Filter = new p5(sortSketch); +p5Filter = new p5(resizeSketch); +p5Filter = new p5(evenOddPixelSketch);