torch [] t; void setup(){ size (600,400); t = new torch[500]; 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(150,0,0); } void loop(){ for (int i = 0; i < t.length; i++){ t[i].trace(); } } void mousePressed(){ background(150,0,0); for (int i = 0; i < t.length; i++){ t[i].x = random(width-2)+1; t[i].y = random(height-2)+1; t[i].d = int(random(4)); } } 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 = green(pixels[xp + yp * width]); if (light){ if (d == 2 && red(pixels[(xp - 1) + yp * width]) >= 10){x-=1; }else if(d == 2 && red(pixels[(xp - 1) + yp * width]) < 10){d = (d+1)%4;} 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)%4;} if (d == 3 && red(pixels[xp + (yp - 1) * width]) >= 10){y-=1; }else if(d == 3 && red(pixels[xp + (yp - 1) * width]) < 10){d = (d+1)%4;} if (d == 1 && red(pixels[xp + (yp + 1) * width]) >= 10){y+=1; }else if(d == 1 && red(pixels[xp + (yp + 1) * width]) < 10){d = (d+1)%4;} }else{ if (d == 2 && green(pixels[(xp - 1) + yp * width]) <= 245){x-=1; }else if(d == 2 && green(pixels[(xp - 1) + yp * width]) > 245){d = (d+1)%4;} if (d == 0 && green(pixels[(xp + 1) + yp * width]) <= 245){x+=1; }else if(d == 0 && green(pixels[(xp + 1) + yp * width]) > 245){d = (d+1)%4;} if (d == 3 && green(pixels[xp + (yp - 1) * width]) <= 245){y-=1; }else if(d == 3 && green(pixels[xp + (yp - 1) * width]) > 245){d = (d+1)%4;} if (d == 1 && green(pixels[xp + (yp + 1) * width]) <= 245){y+=1; }else if(d == 1 && green(pixels[xp + (yp + 1) * width]) > 245){d = (d+1)%4;} } if (x > width - 2){x = 2;} if (x < 2){x = width - 2;} if (y > height - 2){y = 2;} if (y < 2){y = height - 2;} if (light){ stroke(9); }else{ stroke(246); } point(x,y); } }