We are about to switch to a new forum software. Until then we have removed the registration on this forum.
float hue = random(360);
float saturation = random(30, 50); // color's code from openprocessing's user Reona~
float Hue = random(360);
float Saturation = random(50, 100);
float[] xPos = new float[20];
float[] yPos = new float[20];// ellipse
float[] xxPos = new float[5];
float[] yyPos = new float[5];// rect
int A;
int i;
int B;
int C;
int D;
int E;
int F;
void setup() {
size(1000, 610);
frameRate(60);
smooth();
colorMode(HSB, 360, 100, 100);
background(360);
ellipseMode(RADIUS);
rectMode(RADIUS);
A = 20;
B = 570;
C = 530;
D = 690;
E = 650;
F = 610;
for (int i = 0; i < 20; i++) {
xPos[i] = random(1000);
yPos[i] = random(1000);// ellipse
}
for (int z = 0; z < 5; z++) {
xxPos[z] = random(1000);
yyPos[z] = random(1000);// rect
}
}
void draw() {
background(360);
strokeWeight(3);
stroke(260, 80, 100, 120);
noFill();
beginShape();
vertex(mouseX-40, 450);
vertex(mouseX-40, 500);
vertex(mouseX-80, 500);
vertex(mouseX-80, 600);
vertex(mouseX+80, 600);
vertex(mouseX+80, 500);
vertex(mouseX+40, 500);
vertex(mouseX+40, 450);
endShape();// beaker
noStroke();
fill(186, 25, 98);
rect(mouseX, 580, 80, A);//WATER
for (int i = 0; i < 20; i++) {
fill(hue, saturation, 100, 120);
ellipse(xPos[i], yPos[i], 15, 15);
yPos[i]+=2;
if (yPos[i] > height) {
yPos[i] = random(-1000, -500);
}
if (mouseX > 920) {
mouseX = 920;
}
if (mouseX < 80) {
mouseX = 80;
}
}// rock
fill(Hue, Saturation, 100, 120);
for (int z = 0; z < 5; z++) {
rect(xxPos[z], yyPos[z], 20, 20);
yyPos[z]+=2;
if (yyPos[z] > height) {
yyPos[z] = random(-1000, -500);
}
} // rect
if (mouseX-40 < xPos[i] && mouseX+40 > xPos[i] && yPos[i] > 450 )
{
println("good");
xPos[i] = -999999;
yPos[i] = -999999;
A += 5;
}
if (xxPos[i] > mouseX-40 && xxPos[i] < mouseX+40 && yyPos[i] > 450 ) {
xxPos[i] = -999999;
yyPos[i] = -999999;
}
}
In the last two IF statements, I'm trying to increase the value of "A" (the height of the blue rectangle) once the object which controlled by the mouse hit the falling ellipse. But it does not work somehow.
Also could anyone tell me a way to make the "A" value only add one time as the object meets with the ellipse instead of keeping adding 60 times a second?
Thanks a lot!
Answers
first all the condition of xPos and xxPos never change so there was no way for A to increase I wrapped both IF statements in for loops and it works