// Circular buffering demo // only 1 particle is drawn per frame, yet the end result yields // a seemingly infinite number of moving objects without any further slow down // author: info@toxi.co.uk (14/11/03) BImage[] buffers; int currID,nBuffers=16; float xp,yp,angle,speed,dx,dy,r,g,b,brushS; void setup() { size(200,200); ellipseMode(CENTER_DIAMETER); // make up background gradient noStroke(); beginShape(QUADS); fill(96); vertex(0,0); vertex(width,0); fill(128); vertex(width,height); vertex(0,height); endShape(); // setup buffers with the current contents of the main pixel buffer buffers=new BImage[nBuffers]; for(int i=0; i=width) xp-=width; if (yp<0) yp+=height; else if (yp>=height) yp-=height; // 1st draw shadow stroke(0); fill(0,60); ellipse(xp+1,yp+1,brushS,brushS); // then highlight stroke(255,150); noFill(); ellipse(xp,yp,brushS,brushS); // save into current buffer System.arraycopy(pixels,0,buffers[currID].pixels,0,pixels.length); currID=(++currID) % nBuffers; }