How can I delay the display of objects in an array?
in
Programming Questions
•
2 years ago
Hello,
I've got the following code:
RainDrop [] RainDrops = new RainDrop[100]; //Create an array of 100 drops
void setup(){
size(640, 480);
noFill();
stroke(0, 100);
strokeWeight(2);
smooth();
for(int i = 0; i< RainDrops.length; i++){
RainDrops[i] = new RainDrop();
}
}
void draw(){
background(0);
for(int i = 0; i< RainDrops.length; i++){
RainDrops[i].display();
}
}
class RainDrop {
float xPos; //x position of expanding raindrop
float yPos; //y position of expanding raindrop
int ralph; //alpha variable for stroke
RainDrop(){
xPos = random(width);
yPos = random(height);
ralph = 100;
//noFill();
//stroke(0, 100);
//strokeWeight(2);
}
void display(){
stroke(255, ralph);
ellipse(xPos, yPos, 1000/ralph, 1000/ralph);
if(ralph > 1){
ralph--;
} else{
ralph = 100;
}
}
}
Basically, I want to make it "rain" but I'm stuck as to how I should offset the display of the objects to make the patterning more natural. Any help is greatly appreciated!
I've got the following code:
RainDrop [] RainDrops = new RainDrop[100]; //Create an array of 100 drops
void setup(){
size(640, 480);
noFill();
stroke(0, 100);
strokeWeight(2);
smooth();
for(int i = 0; i< RainDrops.length; i++){
RainDrops[i] = new RainDrop();
}
}
void draw(){
background(0);
for(int i = 0; i< RainDrops.length; i++){
RainDrops[i].display();
}
}
class RainDrop {
float xPos; //x position of expanding raindrop
float yPos; //y position of expanding raindrop
int ralph; //alpha variable for stroke
RainDrop(){
xPos = random(width);
yPos = random(height);
ralph = 100;
//noFill();
//stroke(0, 100);
//strokeWeight(2);
}
void display(){
stroke(255, ralph);
ellipse(xPos, yPos, 1000/ralph, 1000/ralph);
if(ralph > 1){
ralph--;
} else{
ralph = 100;
}
}
}
Basically, I want to make it "rain" but I'm stuck as to how I should offset the display of the objects to make the patterning more natural. Any help is greatly appreciated!
1