Hope this is the right forum, anyway this is my first piece of processing beyond just "ohh look a line" so its probably quite a mess and maybe a few things I don't need but anyway works as intended in the enviroment but only the drawing works in a browser.
Anyone got any idea why? Cheers
left mouse:draw
right mouse:delete
Version 0091 Windows XP
---------------------------------
Code:
int maxdrops = 3000;
Water[] drops = new Water[maxdrops];
int numdrops = 1;
void setup(){
size(400,400);
colorMode(RGB);
background(0);
}
void draw(){
//Tap
if(numdrops<maxdrops){
drops[numdrops] = new Water(200,0);
numdrops++;
}
//Paint
if(mousePressed) {
if(mouseButton == LEFT){
//Draw
stroke(100,174,81);
strokeWeight(8);
line(mouseX, mouseY, pmouseX, pmouseY);
strokeWeight(1);
}
//Erase
if(mouseButton == RIGHT){
stroke(0);
strokeWeight(8);
line(mouseX, mouseY, pmouseX, pmouseY);
strokeWeight(1);
}
}
for (int i = 1; i < numdrops; i++) {
//int selected = min((int)random(numdrops), numdrops - 1);
drops[i].update();
}
}
class Water {
int xpos,ypos,lastx,lasty,nextx,nexty,left,right,decide;
Water (int x, int y) {
xpos = x;
ypos = y;
}
void update() {
//make last
this.lastx = this.xpos;
this.lasty = this.ypos;
//check down
if(get(this.xpos,this.ypos+1) == -16777216){
this.nextx = this.xpos;
this.nexty = this.ypos;
this.nexty++;
} else {
//check left and right
this.decide = int(random(2));
if(this.decide == 0){
//left
if(get(this.xpos-1,ypos) == -16777216){
this.nextx = this.xpos;
this.nexty = this.ypos;
this.nextx--;
}
//end
}
if(this.decide == 1){
//right
if(get(this.xpos+1,ypos) == -16777216){
this.nextx = this.xpos;
this.nexty = this.ypos;
this.nextx++;
}
//end
}
}
//send to top
if((this.xpos == 200) && (this.ypos == 399) && (numdrops >= 1000)){
this.nextx = 201;
this.nexty = 0;
}
//delete last
stroke(0,0,0);
point(this.lastx,this.lasty);
//make new
stroke(0,172,255);
point(this.nextx,this.nexty);
//current position
this.xpos = this.nextx;
this.ypos = this.nexty;
}
}