64 lines
1.4 KiB
Plaintext
64 lines
1.4 KiB
Plaintext
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);
|
|
} |