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;
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); } } }
I am relatively new to Processing, and I am trying to connect Processing and Arduino with Firmata.
I am using the 32 bit version of Processing and Java (a previous problem with Firmata forced me to).
Now, when I try to run one of the 3 examples given with the library, such as the arduino_pwm example, I get this error:
illegalAccessError: tried to access class processing.core.PApplet$RegisteredMethods from class cc.arduino.Arduino$SerialProxy
Stable Library
=========================================
Native lib Version = RXTX-2.1-7
Java lib Version = RXTX-2.1-7
Exception in thread "Animation Thread" java.lang.IllegalAccessError: tried to access class processing.core.PApplet$RegisteredMethods from class cc.arduino.Arduino$SerialProxy
at cc.arduino.Arduino$SerialProxy.<init>(Arduino.java:119)
at cc.arduino.Arduino.<init>(Arduino.java:168)
at arduino_pwm.setup(arduino_pwm.java:32)
at processing.core.PApplet.handleDraw(PApplet.java:2103)
at processing.core.PGraphicsJava2D.requestDraw(PGraphicsJava2D.java:190)
at processing.core.PApplet.run(PApplet.java:2006)
at java.lang.Thread.run(Thread.java:662)