summaryrefslogtreecommitdiff
path: root/Year_2/IandM/02232021_1
diff options
context:
space:
mode:
Diffstat (limited to 'Year_2/IandM/02232021_1')
-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
3 files changed, 77 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());
+ }
+}