torch [] t; void setup(){ size (400,300); t = new torch[10000]; for (int i = 0; i < t.length/2; i++){ t[i] = new torch(random(width-2)+1,random(height-2)+1,int(random(4)),false); } for (int i = t.length/2; i < t.length; i++){ t[i] = new torch(random(width-2)+1,random(height-2)+1,int(random(4)),true); } background(128); } void loop(){ for (int i = 0; i < t.length; i++){ t[i].trace(); } } void mousePressed(){ background(128); } class torch{ float x,y; int d; boolean light; torch(float x, float y, int d, boolean light){ this.x = x; this.y = y; this.d = d; this.light = light; } void trace(){ int xp = int(x); int yp = int(y); float c = red(pixels[xp + yp * width]); if (light){ if (d == 4 && red(pixels[(xp - 1) + yp * width]) > 10){x-=1; }else if(d == 4 && red(pixels[(xp - 1) + yp * width]) <= 10){d = (d+1)%8;} if (d == 0 && red(pixels[(xp + 1) + yp * width]) > 10){x+=1; }else if(d == 0 && red(pixels[(xp + 1) + yp * width]) <= 10){d = (d+1)%8;} if (d == 6 && red(pixels[xp + (yp - 1) * width]) > 10){y-=1; }else if(d == 6 && red(pixels[xp + (yp - 1) * width]) <= 10){d = (d+1)%8;} if (d == 2 && red(pixels[xp + (yp + 1) * width]) > 10){y+=1; }else if(d == 2 && red(pixels[xp + (yp + 1) * width]) <= 10){d = (d+1)%8;} if (d == 5 && red(pixels[(xp - 1) + (yp - 1) * width]) > 10){x-=1; y-=1; }else if(d == 5 && red(pixels[(xp - 1) + (yp - 1) * width]) <= 10){d = (d+1)%8;} if (d == 7 && red(pixels[(xp + 1) + (yp + 1) * width]) > 10){x+=1; y+=1; }else if(d == 7 && red(pixels[(xp + 1) + (yp + 1) * width]) <= 10){d = (d+1)%8;} if (d == 3 && red(pixels[(xp + 1) + (yp - 1) * width]) > 10){y-=1; x+=1; }else if(d == 3 && red(pixels[(xp + 1) + (yp - 1) * width]) <= 10){d = (d+1)%8;} if (d == 1 && red(pixels[(xp - 1) + (yp + 1) * width]) > 10){y+=1; x-=1; }else if(d == 1 && red(pixels[(xp - 1) + (yp + 1) * width]) <= 10){d = (d+1)%8;} xp = int(x); yp = int(y); if (red(pixels[xp + yp * width])- 10 > 0){c = red(pixels[xp + yp * width])- 10;} }else{ if (d == 4 && red(pixels[(xp - 1) + yp * width]) <= 245){x-=1; }else if(d == 4 && red(pixels[(xp - 1) + yp * width]) > 245){d = (d+1)%8;} if (d == 0 && red(pixels[(xp + 1) + yp * width]) <= 245){x+=1; }else if(d == 0 && red(pixels[(xp + 1) + yp * width]) > 245){d = (d+1)%8;} if (d == 6 && red(pixels[xp + (yp - 1) * width]) <= 245){y-=1; }else if(d == 6 && red(pixels[xp + (yp - 1) * width]) > 245){d = (d+1)%8;} if (d == 2 && red(pixels[xp + (yp + 1) * width]) <= 245){y+=1; }else if(d == 2 && red(pixels[xp + (yp + 1) * width]) > 245){d = (d+1)%8;} if (d == 5 && red(pixels[(xp - 1) + (yp - 1) * width]) <= 245){x-=1; y-=1; }else if(d == 5 && red(pixels[(xp - 1) + (yp - 1) * width]) > 245){d = (d+1)%8;} if (d == 3 && red(pixels[(xp + 1) + (yp + 1) * width]) <= 245){x+=1; y+=1; }else if(d == 3 && red(pixels[(xp + 1) + (yp + 1) * width]) > 245){d = (d+1)%8;} if (d == 7 && red(pixels[(xp + 1) + (yp - 1) * width]) <= 245){y-=1; x+=1; }else if(d == 7 && red(pixels[(xp + 1) + (yp - 1) * width]) > 245){d = (d+1)%8;} if (d == 1 && red(pixels[(xp - 1) + (yp + 1) * width]) <= 245){y+=1; x-=1; }else if(d == 1 && red(pixels[(xp - 1) + (yp + 1) * width]) > 245){d = (d+1)%8;} xp = int(x); yp = int(y); if (red(pixels[xp + yp * width])+ 10 < 255){c = red(pixels[xp + yp * width])+ 10;} } if (x > width - 2){x = 2;} if (x < 2){x = width - 2;} if (y > height - 2){y = 2;} if (y < 2){y = height - 2;} stroke(c); point(x,y); } }