From 49805bf316bd9ed1a8dcbd829a0c28b9399d1ff3 Mon Sep 17 00:00:00 2001 From: Santo Cariotti Date: Tue, 23 Feb 2021 19:07:56 +0100 Subject: i&m: exercises of 23rd feb --- Year_2/IandM/02232021_2/Exercise2.pde | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 Year_2/IandM/02232021_2/Exercise2.pde (limited to 'Year_2/IandM/02232021_2/Exercise2.pde') diff --git a/Year_2/IandM/02232021_2/Exercise2.pde b/Year_2/IandM/02232021_2/Exercise2.pde new file mode 100755 index 0000000..28d29b4 --- /dev/null +++ b/Year_2/IandM/02232021_2/Exercise2.pde @@ -0,0 +1,59 @@ +void setup() { + size(768, 256); + PImage img = loadImage("monkey.jpg"); + img.resize(256, 256); + img.filter(GRAY); + + image(img, 0, 0); + + PImage revimg = rev(img); + image(revimg, 256, 0); + + int random_number = (int)random(5, 15); // [5, 15) + image(mass(revimg, random_number), 512, 0); +} + +PImage rev(PImage I) { + PImage out = I.copy(); + int t; + + for (int row = 0; row < out.width; ++row) { + for (int i = 0, j = out.width-1; i < out.width/2; ++i, --j) { + t = out.get(i, row); + out.set(i, row, out.get(j, row)); + out.set(j, row, t); + } + } + + // yellow pixels + for (int i = 0; i < out.width; ++i) + out.set(i, i, color(#EFFC38)); + + + return out; +} + +PImage mass(PImage I, int n) { + PImage out = createImage(I.width, I.height, RGB); + + // image and array aux + PImage tmp; + float[] tarr = new float[n*n]; + + int off = n/2; + + for(int i = 0; i < out.width; ++i) { + for(int j = 0; j < out.height; ++j) { + tmp = I.get(i-off, j-off, n, n); + + tmp.loadPixels(); + for(int k = 0; k < tmp.pixels.length; ++k) { + tarr[k] = red(tmp.pixels[k]); + } + + out.set(i, j, color(max(tarr))); + } + } + + return out; +} -- cgit v1.2.3-18-g5258