int nrOfWorms=500; Wormtype[] worm=new Wormtype[nrOfWorms+1]; color[][] traces=new color[600+1][300+1]; // array for storing background+wormtrace colors float bgcR,bgcG,bgcB; color backGroundColor; boolean paused=false; void setup() { size(600,300,P3D); bgcR=238; bgcG=229; bgcB=191; backGroundColor=color(bgcR,bgcG,bgcB); // FILL TRACE ARRAY WITH BACKGROUND COLOR: for (int x=1;x<=width;x++) { for (int y=1;y<=height;y++) { traces[x][y]=color(238,229,191); } } // CREATE WORMS: for (int i=1;i<=nrOfWorms;i++) { worm[i]=new Wormtype(i); } } void draw() { // CLEAR SCREEN: background(backGroundColor); // DRAW TRACES: for (int x=1;x<=width;x++) { for (int y=1;y<=height;y++) { set(x,y,traces[x][y]); } } // DRAW WORMS for (int i=1;i<=nrOfWorms;i++) { worm[i].update(); } } void pointScreen(float x,float y,boolean trace, color wormColor) { color tCol; while (x<1) { x+=width; } while (x>width) { x-=width; } while (y<1) { y+=height; } while (y>height) { y-=height; } point(x,y); if (trace) { tCol=traces[int(x)][int(y)]; tCol=color((15*red(tCol)+red(wormColor))/16.0,(15*green(tCol)+green(wormColor))/16.0,(15*blue(tCol)+blue(wormColor))/16.0); traces[int(x)][int(y)]=tCol; } } float warpedX(float input) { while (input<1) { input+=width; } while (input>width) { input-=width; } return input; } float warpedY(float input) { while (input<1) { input+=height; } while (input>height) { input-=height; } return input; }