46 lines
1.0 KiB
Plaintext
46 lines
1.0 KiB
Plaintext
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);
|
|
} |