diff --git a/Lektion 2/Kollisionserkennung/1_FarbButtons/FarbButtons.pde b/Lektion 2/Kollisionserkennung/1_FarbButtons/FarbButtons.pde new file mode 100644 index 0000000..7fcd1a3 --- /dev/null +++ b/Lektion 2/Kollisionserkennung/1_FarbButtons/FarbButtons.pde @@ -0,0 +1,64 @@ +int size = 150; + +void setup() { + size(570, 570); + noStroke(); + background(220); +} + +void draw() { + int x1 = width / 2 - size / 2; + int y1 = 105 - size / 2; + int x2 = x1; + int y2 = 285 - size / 2; + int x3 = x1; + int y3 = 475 - size / 2; + + // setze Buttons + drawButton(x1, y1, color(255, 0, 0), "Rot"); + drawButton(x2, y2, color(0, 255, 0), "Grün"); + drawButton(x3, y3, color(0, 0, 255), "Blau"); + + // Klick außerhalb der Elemente + if (!(x1 <= mouseX && + y1 <= mouseY && + mouseX <= x1 + size && + mouseY <= y1 + size) && + !(x2 <= mouseX && + y2 <= mouseY && + mouseX <= x2 + size && + mouseY <= y2 + size) && + !(x3 <= mouseX && + y3 <= mouseY && + mouseX <= x3 + size && + mouseY <= y3 + size)) { + + if (mousePressed) { + background(220); + } + } +} + +void drawButton(int x, int y, color paint, String title) { + // setze Füllfarbe ... + if (x <= mouseX && + y <= mouseY && + mouseX <= x + size && + mouseY <= y + size) { + if (mousePressed) { + background(paint); + } + + fill(200); + } + // setze Rechteck + rect(x, y, size, size); + + // setze Text + fill(0); + textAlign(CENTER); + text(title, x + size / 2, y + size / 2); + + + fill(255); +} \ No newline at end of file diff --git a/Lektion 2/Kollisionserkennung/1_FarbButtons/out/FarbButtons.class b/Lektion 2/Kollisionserkennung/1_FarbButtons/out/FarbButtons.class new file mode 100644 index 0000000..e0aa543 Binary files /dev/null and b/Lektion 2/Kollisionserkennung/1_FarbButtons/out/FarbButtons.class differ diff --git a/Lektion 2/Kollisionserkennung/1_FarbButtons/out/source/FarbButtons.java b/Lektion 2/Kollisionserkennung/1_FarbButtons/out/source/FarbButtons.java new file mode 100644 index 0000000..a347c4a --- /dev/null +++ b/Lektion 2/Kollisionserkennung/1_FarbButtons/out/source/FarbButtons.java @@ -0,0 +1,93 @@ +/* autogenerated by Processing revision 1293 on 2023-09-27 */ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class FarbButtons extends PApplet { + +int size = 150; + +public void setup() { + /* size commented out by preprocessor */; + noStroke(); + background(220); +} + +public void draw() { + int x1 = width / 2 - size / 2; + int y1 = 105 - size / 2; + int x2 = x1; + int y2 = 285 - size / 2; + int x3 = x1; + int y3 = 475 - size / 2; + + drawButton(x1, y1, color(255, 0, 0), "Rot"); + drawButton(x2, y2, color(0, 255, 0), "Grün"); + drawButton(x3, y3, color(0, 0, 255), "Blau"); + + // Klick außerhalb der Elemente + if (!(x1 <= mouseX && + y1 <= mouseY && + mouseX <= x1 + size && + mouseY <= y1 + size) && + !(x2 <= mouseX && + y2 <= mouseY && + mouseX <= x2 + size && + mouseY <= y2 + size) && + !(x3 <= mouseX && + y3 <= mouseY && + mouseX <= x3 + size && + mouseY <= y3 + size)) { + + if (mousePressed) { + background(220); + } + } +} + +public void drawButton(int x, int y, int paint, String title) { + // setze Füllfarbe ... + if (x <= mouseX && + y <= mouseY && + mouseX <= x + size && + mouseY <= y + size) { + if (mousePressed) { + background(paint); + } + + fill(200); + } + // setze Rechteck + rect(x, y, size, size); + + // setze Text + fill(0); + textAlign(CENTER); + text(title, x + size / 2, y + size / 2); + + + fill(255); +} + + + public void settings() { size(570, 570); } + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "FarbButtons" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} diff --git a/Lektion 2/Kollisionserkennung/2_rectMode/out/rectMode.class b/Lektion 2/Kollisionserkennung/2_rectMode/out/rectMode.class new file mode 100644 index 0000000..11211bd Binary files /dev/null and b/Lektion 2/Kollisionserkennung/2_rectMode/out/rectMode.class differ diff --git a/Lektion 2/Kollisionserkennung/2_rectMode/out/source/rectMode.java b/Lektion 2/Kollisionserkennung/2_rectMode/out/source/rectMode.java new file mode 100644 index 0000000..45af315 --- /dev/null +++ b/Lektion 2/Kollisionserkennung/2_rectMode/out/source/rectMode.java @@ -0,0 +1,75 @@ +/* autogenerated by Processing revision 1293 on 2023-09-27 */ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class rectMode extends PApplet { + +int size = 150; // Durchmesser + +public void setup() { + /* size commented out by preprocessor */; + noStroke(); + background(220); +} + +public void draw() { + drawButton(width / 2, 105, color(255, 0, 0), "Rot"); + drawButton(width / 2, 285, color(0, 255, 0), "Grün"); + drawButton(width / 2, 475, color(0, 0, 255), "Blau"); + + // Klick außerhalb der Elemente + if (dist(mouseX, mouseY, width / 2, 105) > size / 2 && + dist(mouseX, mouseY, width / 2, 285) > size / 2 && + dist(mouseX, mouseY, width / 2, 475) > size / 2) { + + if (mousePressed) { + background(220); + } + } +} + +public void drawButton(int x, int y, int paint, String title) { + // setze Füllfarbe ... + if (dist(mouseX, mouseY, x, y) < size / 2) { + if (mousePressed) { + background(paint); + } + + fill(200); + } + // setze Rechteck + rectMode(CENTER); + rect(x, y, size, size); + + // setze Text + fill(0); + textAlign(CENTER); + text(title, x, y); + + + fill(255); +} + + + public void settings() { size(570, 570); } + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "rectMode" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} diff --git a/Lektion 2/Kollisionserkennung/2_rectMode/rectMode.pde b/Lektion 2/Kollisionserkennung/2_rectMode/rectMode.pde new file mode 100644 index 0000000..76f1875 --- /dev/null +++ b/Lektion 2/Kollisionserkennung/2_rectMode/rectMode.pde @@ -0,0 +1,46 @@ +int size = 150; // Durchmesser + +void setup() { + size(570, 570); + noStroke(); + background(220); +} + +void draw() { + // setze Buttons + drawButton(width / 2, 105, color(255, 0, 0), "Rot"); + drawButton(width / 2, 285, color(0, 255, 0), "Grün"); + drawButton(width / 2, 475, color(0, 0, 255), "Blau"); + + // Klick außerhalb der Elemente + if (dist(mouseX, mouseY, width / 2, 105) > size / 2 && + dist(mouseX, mouseY, width / 2, 285) > size / 2 && + dist(mouseX, mouseY, width / 2, 475) > size / 2) { + + if (mousePressed) { + background(220); + } + } +} + +void drawButton(int x, int y, color paint, String title) { + // setze Füllfarbe ... + if (dist(mouseX, mouseY, x, y) < size / 2) { + if (mousePressed) { + background(paint); + } + + fill(200); + } + // setze Rechteck + rectMode(CENTER); + rect(x, y, size, size); + + // setze Text + fill(0); + textAlign(CENTER); + text(title, x, y); + + + fill(255); +} \ No newline at end of file diff --git a/Lektion 2/Kollisionserkennung/3_UeberlappendeButtons/UeberlappendeButtons.pde b/Lektion 2/Kollisionserkennung/3_UeberlappendeButtons/UeberlappendeButtons.pde new file mode 100644 index 0000000..a07da3e --- /dev/null +++ b/Lektion 2/Kollisionserkennung/3_UeberlappendeButtons/UeberlappendeButtons.pde @@ -0,0 +1,35 @@ +int x1 = 200; +int y1 = 100; +int x2 = 100; +int y2 = 200; +int size = 200; + +void setup() { + size(800, 600); +} + +void draw() { + // setze hintergrund + background(255); + noFill(); + + // setze rechtecke + rect(x1, y1, size, size); + rect(x2, y2, size, size); + + // pruefung ob mauszeiger in rechteck ist + boolean isInRect1 = mouseX >= x1 && mouseY >= y1 && mouseX <= x1 + size && mouseY <= y1 + size; + boolean isInRect2 = mouseX >= x2 && mouseY >= y2 && mouseX <= x2 + size && mouseY <= y2 + size; + + if (isInRect1 && isInRect2) { // mauszeiger in schnittmenge + fill(0, 0, 255); + } else if (isInRect1) { // mauszeiger in rechteck 1 + fill(255, 0, 0); + } else if (isInRect2) { // mauszeiger in rechteck 2 + fill(0, 255, 0); + } else { + noFill(); // mauszeiger außerhalb der rechtecke + } + + ellipse(mouseX, mouseY, 20, 20); +} \ No newline at end of file diff --git a/Lektion 2/Kollisionserkennung/3_UeberlappendeButtons/out/UeberlappendeButtons.class b/Lektion 2/Kollisionserkennung/3_UeberlappendeButtons/out/UeberlappendeButtons.class new file mode 100644 index 0000000..799f662 Binary files /dev/null and b/Lektion 2/Kollisionserkennung/3_UeberlappendeButtons/out/UeberlappendeButtons.class differ diff --git a/Lektion 2/Kollisionserkennung/3_UeberlappendeButtons/out/source/UeberlappendeButtons.java b/Lektion 2/Kollisionserkennung/3_UeberlappendeButtons/out/source/UeberlappendeButtons.java new file mode 100644 index 0000000..c29ab03 --- /dev/null +++ b/Lektion 2/Kollisionserkennung/3_UeberlappendeButtons/out/source/UeberlappendeButtons.java @@ -0,0 +1,65 @@ +/* autogenerated by Processing revision 1293 on 2023-09-27 */ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class UeberlappendeButtons extends PApplet { + +int x1 = 200; +int y1 = 100; +int x2 = 100; +int y2 = 200; +int size = 200; + +public void setup() { + /* size commented out by preprocessor */; +} + +public void draw() { + // setze hintergrund + background(255); + noFill(); + + // setze rechtecke + rect(x1, y1, size, size); + rect(x2, y2, size, size); + + // pruefung ob mauszeiger in rechteck ist + boolean isInRect1 = mouseX >= x1 && mouseY >= y1 && mouseX <= x1 + size && mouseY <= y1 + size; + boolean isInRect2 = mouseX >= x2 && mouseY >= y2 && mouseX <= x2 + size && mouseY <= y2 + size; + + if (isInRect1 && isInRect2) { // mauszeiger in schnittmenge + fill(0, 0, 255); + } else if (isInRect1) { // mauszeiger in rechteck 1 + fill(255, 0, 0); + } else if (isInRect2) { // mauszeiger in rechteck 2 + fill(0, 255, 0); + } else { + noFill(); // mauszeiger außerhalb der rechtecke + } + + ellipse(mouseX, mouseY, 20, 20); +} + + + public void settings() { size(800, 600); } + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "UeberlappendeButtons" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} diff --git a/Lektion 2/Kollisionserkennung/4_KollisionPunktLinie/KollisionPunktLinie.pde b/Lektion 2/Kollisionserkennung/4_KollisionPunktLinie/KollisionPunktLinie.pde new file mode 100644 index 0000000..8b06ff7 --- /dev/null +++ b/Lektion 2/Kollisionserkennung/4_KollisionPunktLinie/KollisionPunktLinie.pde @@ -0,0 +1,28 @@ +float ax = 50; // x-Position von Punkt a + +float bx = 5; // x-Position des Startpunkts der Linie b +float bwidth = 30; // Breite der Linie b + +void draw() { + background(0); + strokeWeight(5); + + stroke(0,255,0); + point(ax, ax); // setze punkt + + if (bx + bwidth >= ax && bx <= ax) { // wenn linie innerhalb x von punkt + stroke(255, 0, 0); // setze farbe auf rot + } else { + stroke(255); // setze farbe auf weiß + } + + line(bx, 60, bx + bwidth, 60); // setze linie + + if (keyPressed) { + if(keyCode == LEFT) { + bx -= 2; + } else if (keyCode == RIGHT) { + bx += 2; + } +} +} \ No newline at end of file diff --git a/Lektion 2/Kollisionserkennung/4_KollisionPunktLinie/out/KollisionPunktLinie.class b/Lektion 2/Kollisionserkennung/4_KollisionPunktLinie/out/KollisionPunktLinie.class new file mode 100644 index 0000000..2cf03fe Binary files /dev/null and b/Lektion 2/Kollisionserkennung/4_KollisionPunktLinie/out/KollisionPunktLinie.class differ diff --git a/Lektion 2/Kollisionserkennung/4_KollisionPunktLinie/out/source/KollisionPunktLinie.java b/Lektion 2/Kollisionserkennung/4_KollisionPunktLinie/out/source/KollisionPunktLinie.java new file mode 100644 index 0000000..7bb0b5c --- /dev/null +++ b/Lektion 2/Kollisionserkennung/4_KollisionPunktLinie/out/source/KollisionPunktLinie.java @@ -0,0 +1,56 @@ +/* autogenerated by Processing revision 1293 on 2023-09-27 */ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class KollisionPunktLinie extends PApplet { + +float ax = 50; // x-Position von Punkt a + +float bx = 5; // x-Position des Startpunkts der Linie b +float bwidth = 30; // Breite der Linie b + +public void draw() { + background(0); + strokeWeight(5); + + stroke(0,255,0); + point(ax, ax); + + if (bx + bwidth >= ax && bx <= ax) { + stroke(255, 0, 0); + } else { + stroke(255); + } + + line(bx, 60, bx + bwidth, 60); + + if (keyPressed) { + if(keyCode == LEFT) { + bx -= 2; + } else if (keyCode == RIGHT) { + bx += 2; + } +} +} + + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "KollisionPunktLinie" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +} diff --git a/Lektion 2/Kollisionserkennung/5_KollisionLinieLinie/KollisionLinieLinie.pde b/Lektion 2/Kollisionserkennung/5_KollisionLinieLinie/KollisionLinieLinie.pde new file mode 100644 index 0000000..d1ee262 --- /dev/null +++ b/Lektion 2/Kollisionserkennung/5_KollisionLinieLinie/KollisionLinieLinie.pde @@ -0,0 +1,33 @@ +float ax = 60; // x-Position des Startpunkts der Linie a +float awidth = 30; // Breite der Linie a + +float bx = 5; // x-Position des Startpunkts der Linie b +float bwidth = 40; // Breite der Linie b + +void setup() { + size(150, 100); +} + +void draw() { + background(0); + strokeWeight(4); + + stroke(0,255,0); + line(ax, 50, ax + awidth, 50); // setze linie + + stroke(255); + + if (bx + bwidth >= ax && bx <= ax + awidth) { // wenn line b unter linie a + stroke(255, 0, 0); // setze farbe auf rot + } + + line(bx, 60, bx + bwidth, 60); + + if (keyPressed) { + if(keyCode == LEFT) { + bx -= 2; + } else if (keyCode == RIGHT) { + bx += 2; + } +} +} \ No newline at end of file diff --git a/Lektion 2/Kollisionserkennung/5_KollisionLinieLinie/out/KollisionLinieLinie.class b/Lektion 2/Kollisionserkennung/5_KollisionLinieLinie/out/KollisionLinieLinie.class new file mode 100644 index 0000000..f850b8e Binary files /dev/null and b/Lektion 2/Kollisionserkennung/5_KollisionLinieLinie/out/KollisionLinieLinie.class differ diff --git a/Lektion 2/Kollisionserkennung/5_KollisionLinieLinie/out/source/KollisionLinieLinie.java b/Lektion 2/Kollisionserkennung/5_KollisionLinieLinie/out/source/KollisionLinieLinie.java new file mode 100644 index 0000000..f486829 --- /dev/null +++ b/Lektion 2/Kollisionserkennung/5_KollisionLinieLinie/out/source/KollisionLinieLinie.java @@ -0,0 +1,63 @@ +/* autogenerated by Processing revision 1293 on 2023-09-27 */ +import processing.core.*; +import processing.data.*; +import processing.event.*; +import processing.opengl.*; + +import java.util.HashMap; +import java.util.ArrayList; +import java.io.File; +import java.io.BufferedReader; +import java.io.PrintWriter; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.IOException; + +public class KollisionLinieLinie extends PApplet { + +float ax = 60; // x-Position des Startpunkts der Linie a +float awidth = 30; // Breite der Linie a + +float bx = 5; // x-Position des Startpunkts der Linie b +float bwidth = 40; // Breite der Linie b + +public void setup() { + /* size commented out by preprocessor */; +} + +public void draw() { + background(0); + strokeWeight(4); + + stroke(0,255,0); + line(ax, 50, ax + awidth, 50); + + stroke(255); + + if (bx + bwidth >= ax && bx <= ax + awidth) { + stroke(255, 0, 0); + } + + line(bx, 60, bx + bwidth, 60); + + if (keyPressed) { + if(keyCode == LEFT) { + bx -= 2; + } else if (keyCode == RIGHT) { + bx += 2; + } +} +} + + + public void settings() { size(150, 100); } + + static public void main(String[] passedArgs) { + String[] appletArgs = new String[] { "KollisionLinieLinie" }; + if (passedArgs != null) { + PApplet.main(concat(appletArgs, passedArgs)); + } else { + PApplet.main(appletArgs); + } + } +}