summaryrefslogtreecommitdiff
path: root/Year_2/IandM/02232021_2
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-02-23 19:07:56 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-02-24 19:07:56 +0100
commit49805bf316bd9ed1a8dcbd829a0c28b9399d1ff3 (patch)
tree34fa1afdb30b44bccc9803d0f241c9d97e3862a8 /Year_2/IandM/02232021_2
parentcf228fd6b77a0efbdd4846d41a436663f2ae7eb1 (diff)
i&m: exercises of 23rd feb
Diffstat (limited to 'Year_2/IandM/02232021_2')
-rwxr-xr-xYear_2/IandM/02232021_2/Exercise2.pde59
-rwxr-xr-xYear_2/IandM/02232021_2/data/monkey.jpgbin0 -> 33054 bytes
2 files changed, 59 insertions, 0 deletions
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;
+}
diff --git a/Year_2/IandM/02232021_2/data/monkey.jpg b/Year_2/IandM/02232021_2/data/monkey.jpg
new file mode 100755
index 0000000..76d04f2
--- /dev/null
+++ b/Year_2/IandM/02232021_2/data/monkey.jpg
Binary files differ