We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › I need to fill a bottle
Page Index Toggle Pages: 1
I need to fill a bottle (Read 600 times)
I need to fill a bottle
Apr 18th, 2010, 4:02am
 
Hi im having some trouble on how to make a "bottle get full".
I mean first i got the drops to fall but i cant make the "water" level (just a simple rect shape), to raise.
If anyone could give me an example to how to do it, would be apprectiated.
Re: I need to fill a bottle
Reply #1 - Apr 18th, 2010, 4:59am
 
Not sure how this will fit in with the code you have already written but it might help.
Code:

float waterLevel = 0;

void setup(){
 size(200,200);
 frameRate(60);
}

void draw(){
 background(128);

 // Draw the water
 noStroke();
 fill(0,0,230);
 // Reset the water level when the bottle is nearly full
 if(waterLevel < 100)
   rect(80, 180 - waterLevel, 40, waterLevel);
 else
   waterLevel = 0;

 // Draw the bottle
 stroke(255);
 strokeWeight(2.0);
 noFill();
 rect(80,60,40,120);

 waterLevel += 0.2;
}

Re: I need to fill a bottle
Reply #2 - Apr 18th, 2010, 5:02am
 
thx for the answer mate and it did indeed help me understand how it works, yet the thing is, i want only to make the water level raise when a certain drop "touchs the water"

Re: I need to fill a bottle
Reply #3 - Apr 18th, 2010, 5:13am
 
Code:
float waterLevel = 0;
float dropY = -10;

void setup(){
size(200,200);
frameRate(60);
}

void draw(){
background(128);


// Draw the water
noStroke();
fill(0,0,230);
ellipse(width/2,dropY,5,5);

// Reset the water level when the bottle is nearly full
if(waterLevel < 100)
rect(80, 180 - waterLevel, 40, waterLevel);
else
waterLevel = 0;

// Draw the bottle
stroke(255);
strokeWeight(2.0);
noFill();
rect(80,60,40,120);

if(dropY>180-waterLevel){
waterLevel += 3;
dropY = -10;
}
dropY += 3;


}

Page Index Toggle Pages: 1