Hello!
I've created a sketch that selects a screen amongst several ones when the mouse is pressed. When ScreenA is selected, it should display Rain made of several Drops. But I don't succeed to make each Drop behave independantly. I would like that at a certain height y2, the Drop changes its transparency alphaDrop and at another height y2, reinitialize itself and appears to another place. Currently, when an height y2 is attained, every drops change their alpha, and then every drops are reinitialized together.
I've tryed to use this example http://wiki.processing.org/w/From_several_arrays_to_classes but obviously I'm doing something wrong.
Thanks for your help!
Laura
I've created a sketch that selects a screen amongst several ones when the mouse is pressed. When ScreenA is selected, it should display Rain made of several Drops. But I don't succeed to make each Drop behave independantly. I would like that at a certain height y2, the Drop changes its transparency alphaDrop and at another height y2, reinitialize itself and appears to another place. Currently, when an height y2 is attained, every drops change their alpha, and then every drops are reinitialized together.
I've tryed to use this example http://wiki.processing.org/w/From_several_arrays_to_classes but obviously I'm doing something wrong.
Thanks for your help!
Laura
- Screen[] screens;
int NUMBER_SCREENS = 2;
int lastScreen, currentScreen;
void setup()
{
size(768,768,P2D);
smooth();
background(0);
screens = new Screen[NUMBER_SCREENS];
screens[0] = new ScreenA();
screens[1] = new ScreenB();
currentScreen = 0;
screens[currentScreen].init();
}
void draw()
{
rect(100,100,100,100);
//display current visual
screens[currentScreen].display();
}
void mousePressed() {
{
// pick a different visual
lastScreen=currentScreen;
currentScreen=int(random(screens.length-1));
if( lastScreen <= currentScreen )
currentScreen=(currentScreen+1)%screens.length;
}
// The init function contains the parameters of the clear selected screen
// So call it allows to restart the screen from 0 next time it appears
screens[currentScreen].init();
} - class Screen
{
Screen()
{
}
void init()
{
}
void display()
{
}
void update()
{
}
} - final int DROP_NB = 2;
Drop[] dropArray = new Drop[DROP_NB];
color[] colourArray = {color(26,200,214),color(154,214,226)};
boolean val = false;
class ScreenA extends Screen
{
ScreenA()
{
}
void init()
{
noStroke();
for (int i = 0; i<DROP_NB; i++)
{
dropArray[i] = new Drop(int(random(0,width)),int(random(-100,0)),colourArray[(int) random(colourArray.length)]);
dropArray[i].init();
}
}
void display()
{
background(#0AA08A);
for (int i = 0; i<DROP_NB; i++)
{
boolean t = dropArray[i].rebirth(val);
if (t == true)
{
blop();
init();
}
dropArray[i].update();
dropArray[i].show();
dropArray[i].setSpeed(mouseY/10);
}
}
}
void blop()
{
fill(255,0,0);
rect(100,100,100,100);
} - class Drop
{
int x1;
int y1;
int x2;
int y2;
int speed;
color c;
int alphaDrop;
Drop(int x1, int y1, color c)
{
this.x1 = x1;
this.y1 = y1;
this.c = c;
}
void init()
{
x2 = 20;
y2 = 20;
speed = 1;
alphaDrop= 255;
}
void show()
{
//if (y2<=height)
//{
//println(y2);
fill(c, alphaDrop);
ellipse(x1, y1, x2, y2);
/*}else
{
init();
}*/
}
void update()
{
y2 = y2 + 1 * speed;
if (y2 >=200)
{
alphaDrop = 80;
}
else
{
alphaDrop = 255;
}
}
boolean rebirth(boolean dropCreation)
{
if (y2>=height/2)
{
dropCreation = true;
}
return dropCreation;
}
void setSpeed(int speedRate)
{
speed = speedRate;
}
} - class ScreenB extends Screen
{
ScreenB()
{
}
void init()
{
}
void display()
{
background(#EAD211);
}
}
1