summaryrefslogtreecommitdiff
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
parentcf228fd6b77a0efbdd4846d41a436663f2ae7eb1 (diff)
i&m: exercises of 23rd feb
-rwxr-xr-xYear_2/IandM/02232021_1/Auto.pde29
-rwxr-xr-xYear_2/IandM/02232021_1/AutoElettrica.pde29
-rwxr-xr-xYear_2/IandM/02232021_1/Exercise1.pde19
-rwxr-xr-xYear_2/IandM/02232021_2/Exercise2.pde59
-rwxr-xr-xYear_2/IandM/02232021_2/data/monkey.jpgbin0 -> 33054 bytes
5 files changed, 136 insertions, 0 deletions
diff --git a/Year_2/IandM/02232021_1/Auto.pde b/Year_2/IandM/02232021_1/Auto.pde
new file mode 100755
index 0000000..62c3181
--- /dev/null
+++ b/Year_2/IandM/02232021_1/Auto.pde
@@ -0,0 +1,29 @@
+class Auto {
+ private int posx;
+ private int posy;
+
+ private float velx = random(2, 10); // [2, 10);
+
+ private int MYCOLOR = #007CA0; // this is blue
+
+ public Auto() {
+ this.posx = -60;
+ this.posy = 512/3;
+ }
+
+ public float velx() {
+ return this.velx;
+ }
+
+ void draw() {
+ rectMode(CORNER);
+ noStroke();
+ fill(this.MYCOLOR);
+ rect(posx, posy, 60, 30);
+ posx += velx;
+
+ if(posx >= 512) {
+ posx = -60;
+ }
+ }
+}
diff --git a/Year_2/IandM/02232021_1/AutoElettrica.pde b/Year_2/IandM/02232021_1/AutoElettrica.pde
new file mode 100755
index 0000000..f952b29
--- /dev/null
+++ b/Year_2/IandM/02232021_1/AutoElettrica.pde
@@ -0,0 +1,29 @@
+class AutoElettrica extends Auto {
+ private int MYCOLOR = (int)random(0, 255);
+ private boolean triangle_turn = true;
+
+ AutoElettrica(float velx) {
+ super.velx = velx/2;
+ super.posx = -60;
+ super.posy = 512*2/3;
+ }
+
+ void draw() {
+ rectMode(CORNER);
+ noStroke();
+ fill(this.MYCOLOR);
+ rect(super.posx, super.posy, 60, 30);
+ super.posx += super.velx;
+
+ fill(#EFFC38); // triangle color, this is yellow
+
+ if (this.triangle_turn) {
+ triangle(super.posx+30, super.posy, super.posx+60, super.posy+30, super.posx, super.posy+30);
+ }
+
+ if (super.posx >= 512) {
+ super.posx = -60;
+ this.triangle_turn = !this.triangle_turn;
+ }
+ }
+}
diff --git a/Year_2/IandM/02232021_1/Exercise1.pde b/Year_2/IandM/02232021_1/Exercise1.pde
new file mode 100755
index 0000000..c7bea6b
--- /dev/null
+++ b/Year_2/IandM/02232021_1/Exercise1.pde
@@ -0,0 +1,19 @@
+Auto a = new Auto();
+AutoElettrica ea = new AutoElettrica(a.velx());
+
+void setup() {
+ size(512, 512);
+}
+
+void draw() {
+ background(255);
+ a.draw();
+ ea.draw();
+}
+
+void keyPressed() {
+ if(key == 'R' || key == 'r') {
+ a = new Auto();
+ ea = new AutoElettrica(a.velx());
+ }
+}
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