summaryrefslogtreecommitdiff
path: root/Year_2/IandM
diff options
context:
space:
mode:
authorSanto Cariotti <santo@dcariotti.me>2021-02-20 21:37:23 +0100
committerSanto Cariotti <santo@dcariotti.me>2021-02-20 21:37:23 +0100
commit4a3ed80f51245c429086f2467097c03ec753d35b (patch)
tree2f11b54bc7e382a6a2921e1ea884d7e402d416d5 /Year_2/IandM
parent11a9840840fe74574ed259b3546c412a0659ec0d (diff)
i&m: add exercise of 14th feb 2018
Diffstat (limited to 'Year_2/IandM')
-rw-r--r--Year_2/IandM/02142018/02142018.pde27
-rw-r--r--Year_2/IandM/02142018/Heart.pde67
2 files changed, 94 insertions, 0 deletions
diff --git a/Year_2/IandM/02142018/02142018.pde b/Year_2/IandM/02142018/02142018.pde
new file mode 100644
index 0000000..6bc87ab
--- /dev/null
+++ b/Year_2/IandM/02142018/02142018.pde
@@ -0,0 +1,27 @@
+ArrayList<Heart> hearts = new ArrayList<Heart>();
+void setup() {
+ size(512, 512);
+ background(#011146);
+ frameRate(60);
+}
+void draw() {
+ fill(#011146, 100);
+ rect(0, 0, width, height);
+
+ if ((int)random(1, 101) <= 5) {
+ Heart tmp = new Heart((int)random(0, width), height/2+10);
+ hearts.add(tmp);
+ }
+
+ for (Heart h : hearts) {
+ h.draw();
+ }
+}
+
+void mouseClicked() {
+ for (Heart h : hearts) {
+ if (dist(h.positionx(), h.positiony(), mouseX, mouseY) < 30) {
+ h.die();
+ }
+ }
+}
diff --git a/Year_2/IandM/02142018/Heart.pde b/Year_2/IandM/02142018/Heart.pde
new file mode 100644
index 0000000..8ac93a6
--- /dev/null
+++ b/Year_2/IandM/02142018/Heart.pde
@@ -0,0 +1,67 @@
+
+class Heart {
+ private boolean status;
+ private int posx;
+ private int posy;
+ private float speedx;
+ private float speedy;
+ private int Q = 1948;
+
+ public Heart(int posx, int posy) {
+ this.status = true;
+ this.posx = posx;
+ this.posy = posy;
+ }
+
+ public boolean is_alive() {
+ return this.status;
+ }
+
+ private float f() {
+ return (this.Q%21)/80;
+ }
+
+ public void die() {
+ this.status = false;
+ }
+
+ public void draw() {
+ smooth();
+ noStroke();
+ if (this.is_alive()) {
+ fill(#C41212);
+ } else {
+ fill(#DDDDDD);
+ }
+ this.speedx = random(-5, 6.0);
+ this.speedy = random(3, 8.0);
+ if (!this.is_alive()) {
+ this.speedy += 0.1+this.f();
+ this.posy += this.speedy;
+ } else {
+ this.posy -= this.speedy;
+ }
+
+ this.posx -= this.speedx;
+
+ pushMatrix();
+ translate(-30+this.posx, -5+this.posy);
+
+ beginShape();
+ vertex(50, 15);
+ bezierVertex(50, -5, 90, 5, 50, 40);
+ vertex(50, 15);
+ bezierVertex(50, -5, 10, 5, 50, 40);
+ endShape();
+
+ popMatrix();
+ }
+
+ public int positionx() {
+ return this.posx;
+ }
+
+ public int positiony() {
+ return this.posy;
+ }
+}