int amount = 400; grain[] saltGrain = new grain[amount]; int shift = -10; int dir = 3; PImage shaker; int grainNum = 0; int grainRecycle= 0; boolean fs=true; boolean fsfalse=false; void setup(){ size(400,600); background(0); framerate(100); noStroke(); smooth(); shaker = loadImage("shaker.gif"); for (int i=0; i < amount; i++){ saltGrain[i] = new grain(false); } } void draw(){ background(0); if(mousePressed){ shift = shift + dir; if (shift > 21 || shift < -21){ dir = dir *-1; } grainNum++; if (grainNum>amount-1){ grainNum=0; } grainRecycle = grainNum + 1; if (grainRecycle >amount-1){ grainRecycle = 0; } saltGrain[grainNum].switch2(fs); saltGrain[grainRecycle].switch2(fsfalse); } for (int i=0; i < amount; i++){ saltGrain[i].render(); saltGrain[i].fallDown(); } image(shaker, (mouseX-80)+shift, mouseY-314); }