You should check for<0 (NOT >0
) and do it AFTER the --
command (because it is there to check if the greenSquareSize got < 0 because of --
)
The function setup
size should be the first command in setup()
also, the title can be multiple words, looks better.
void setup() {
size(500, 500);
surface.setTitle("Mal Klein, Mal Gross");
surface.setLocation(250, 250); //Skizze zentriert am Bildschirm anzeigen
}
Remarks
I wouldn’t write Links and Rechts - everybody knows where this is
Groß and Klein is enough
Remember to hit ctrl-t for auto-format in Processing (not in the forum)
So, this is my version:
int greenSquareSize=30;
int redSquareSize=30;
void setup() {
size(500, 500);
surface.setTitle("Mal Klein, Mal Gross");
surface.setLocation(250, 250); //Skizze zentriert am Bildschirm anzeigen
}
void draw() {
background(255, 255, 255);
stroke(0);
//Seitenlinien mit 15 Abstand, parallel zu den Rändern
strokeWeight(3);
line(0, 15, 500, 15);
strokeWeight(3);
line(15, 0, 15, 500);
strokeWeight(3);
line(0, 485, 500, 485);
strokeWeight(3);
line(485, 0, 485, 500);
//Beschriftungen werden angegeben & Schriftgrößen
//fill(0, 255, 0);
//textSize(12);
//text("Links", 20, 10);
fill(0, 255, 0);
textSize(12);
text("Groß", 20, 30);
//fill(0, 255, 0);
//textSize(12);
//text("Rechts", 445, 10);
fill(255, 0, 0);
textSize(12);
text("Groß", 455, 30);
fill(0, 255, 0);
textSize(12);
text("Klein", 20, 480);
//fill(255, 0, 0);
//textSize(12);
//text("Links", 20, 497);
fill(255, 0, 0);
textSize(12);
text("Klein", 455, 480);
//fill(255, 0, 0);
//textSize(12);
//text("Rechts", 445, 497);
//Alle 4 Slider kommen dazu - HERE ARE THE SLIDERS
fill(0, 255, 0);
noStroke();
rect(12, mouseY, 6, 6);
//Hier entgegengesetzt
fill(255, 0, 0);
noStroke();
rect(483, height-mouseY, 6, 6);
fill(255, 0, 0);
noStroke();
ellipse(mouseX, 485, 5, 10);
//Hier auch entgegengesetzt
fill(0, 255, 0);
noStroke();
ellipse(width-mouseX, 16, 5, 10);
//Grünes Quadrat
fill(0, 255, 0);
noStroke();
rect(width-mouseX, mouseY, greenSquareSize, greenSquareSize);
// mouse
if (mouseY > pmouseY) {
greenSquareSize++;
} else if (mouseY < pmouseY) {
greenSquareSize--;
//additional if to check whether greenSquareSize <0 and if so set greenSquareSize = 0
if (greenSquareSize < 0) {
greenSquareSize = 0;
}
}
//Rotes Quadrat
fill(255, 0, 0);
noStroke();
rect(mouseX, height-mouseY, redSquareSize, redSquareSize);
// mouse
if (mouseY > pmouseY) {
redSquareSize++;
} else if (mouseY < pmouseY) {
redSquareSize--;
if (redSquareSize < 0) {
redSquareSize = 0;
}
}//else if
}//func
//
Sliders
A slider is rectangle on a bar, like in the processing editor on the right side to scroll up and down.
Your sliders don’t do that really.
For a slider you click the green circle on the left (for example) and drag it with the mouse.
Only then the green box changes its size.
Here is an example with the vertical slider (you click the green circle on the left and drag it with the mouse). That’s also very nice!
- Using 3 new variables before setup() and mousePressed() and mouseReleased() and a few new lines in draw().
The slider position is stored and mapped to the rectangle size.
You can change the slider position with the mouse but after dragging you can move the mouse independent from the slider again (because the slider position is stored).
int greenSquareSize=30;
int redSquareSize=30;
// Green slider
float slider1x=12;
float slider1y=300;
boolean slider1Hold=false;
void setup() {
size(500, 500);
surface.setTitle("Mal Klein, Mal Gross");
surface.setLocation(250, 250); //Skizze zentriert am Bildschirm anzeigen
}
void draw() {
background(255, 255, 255);
stroke(0);
//Seitenlinien mit 15 Abstand, parallel zu den Rändern
strokeWeight(3);
line(0, 15, 500, 15);
strokeWeight(3);
line(15, 0, 15, 500);
strokeWeight(3);
line(0, 485, 500, 485);
strokeWeight(3);
line(485, 0, 485, 500);
//Beschriftungen werden angegeben & Schriftgrößen
//fill(0, 255, 0);
//textSize(12);
//text("Links", 20, 10);
fill(0, 255, 0);
textSize(12);
text("Groß", 20, 30);
fill(255, 0, 0);
textSize(12);
text("Groß", 455, 30);
fill(0, 255, 0);
textSize(12);
text("Klein", 20, 480);
fill(255, 0, 0);
textSize(12);
text("Klein", 455, 480);
//Alle 4 Slider kommen dazu - HERE ARE THE SLIDERS
fill(0, 255, 0);
noStroke();
rect(slider1x, slider1y, 6, 6);
//Hier entgegengesetzt
fill(255, 0, 0);
noStroke();
rect(483, height-mouseY, 6, 6);
fill(255, 0, 0);
noStroke();
ellipse(mouseX, 485, 5, 10);
//Hier auch entgegengesetzt
fill(0, 255, 0);
noStroke();
ellipse(width-mouseX, 16, 5, 10);
//Grünes Quadrat
fill(0, 255, 0);
noStroke();
rect(width/2, 200, greenSquareSize, greenSquareSize);
//Rotes Quadrat
fill(255, 0, 0);
noStroke();
rect(map(mouseX, 0, width, 15, width-15), height-mouseY, redSquareSize, redSquareSize);
// mouse
if (mouseY > pmouseY) {
redSquareSize++;
} else if (mouseY < pmouseY) {
redSquareSize--;
if (redSquareSize < 0) {
redSquareSize = 0;
}
}//else if
if (slider1Hold) {
slider1y=map(mouseY, 0, height, 15, height-15-8);
slider1y=constrain(slider1y, 15, height-15-8);
greenSquareSize = int(map(slider1y, 15, height-15, 10, 155));
}
greenSquareSize = int(map(slider1y, 15, height-15,
155, 15));
}//func
void mousePressed() {
if (dist(mouseX, mouseY, slider1x, slider1y) < 12) {
// hold=true;
slider1Hold=true;
}
}//func
void mouseReleased() {
slider1Hold=false;
}
//
Warm regards,
Chrisir