Merge branch 'main' into 'main'
added Kollisionserkennung See merge request maximilian.ruhm/processing-projektarbeit!1
This commit is contained in:
commit
f933a9f7fe
64
Lektion 2/Kollisionserkennung/1_FarbButtons/FarbButtons.pde
Normal file
64
Lektion 2/Kollisionserkennung/1_FarbButtons/FarbButtons.pde
Normal file
@ -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);
|
||||
}
|
||||
Binary file not shown.
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
BIN
Lektion 2/Kollisionserkennung/2_rectMode/out/rectMode.class
Normal file
BIN
Lektion 2/Kollisionserkennung/2_rectMode/out/rectMode.class
Normal file
Binary file not shown.
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
46
Lektion 2/Kollisionserkennung/2_rectMode/rectMode.pde
Normal file
46
Lektion 2/Kollisionserkennung/2_rectMode/rectMode.pde
Normal file
@ -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);
|
||||
}
|
||||
@ -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);
|
||||
}
|
||||
Binary file not shown.
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Binary file not shown.
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user