Falling Effect
in
Programming Questions
•
1 years ago
Hey all,
I'm trying to make a 'falling' effect, such that an object simply translates down the screen. However, instead of the object falling, all I get is the object takes up the entire length of the screen.
The rest of the code essentially randomly places some ellipses (the aesthetic I'm eventually looking for is icicles) along the top of the screen, and the icicles slowly grow down. After a certain amount of time, I'd like them to 'detach' from the top of the screen and fall. The 'creep' works just fine, but the falling has some work to be done to it.
I'm not sure if I need a way to clear the screen in the fall() for loop, so that the icicles don't seem to streak down the screen, and I can't figure out why they're not detaching from the top. Any suggestions?
//-----------------Globals
Icicle icicle1;
Icicle icicle2;
Icicle icicle3;
int count = 0;
float delta = 0;
int numIce = 5;
Icicle[] ice = new Icicle[numIce];
//-----------------Setup
void setup(){
size(500,750);
background(255);
smooth();
noStroke();
for (int i = 0; i < ice.length; i++) {
ice[i] = new Icicle(color(0,0,255), random(width), random(0.25*height), 10);
}
}
//-----------------Main Loop
void draw(){
fill(255,80);
rect(0,0,width,height);
for (int i = 0; i < ice.length; i++) {
ice[i].creep();
}
if (count == 50) {
for (int i = 0; i < ice.length; i++) {
ice[i].fall();
}
count = 0;
}
count += 1;
//saveFrame("image###.jpg");
}
//-----------------Defined Classes
class Icicle {
color ice_color;
float xstart;
float endHeight;
float xwidth;
Icicle(color temp_color, float temp_xstart, float temp_endHeight, float temp_xwidth){
ice_color = temp_color;
xstart = temp_xstart;
endHeight = temp_endHeight;
xwidth = temp_xwidth;
}
void creep() {
fill(ice_color);
ellipse(xstart,0,xwidth,endHeight);
endHeight += 2;
}
void fall() {
for(delta = 0; delta < height; delta += 1) {
fill(0,10,200,180);
ellipse(xstart,delta,xwidth,endHeight);
}
}
}
1