import java.lang.*; public class bees06 extends PApplet { final int XS = 31; final int YS = 30; PImage[] frame = new PImage[324]; BeeCell[][] beeCell = new BeeCell[XS][YS]; BeeCell b; int i,j; int delay = 0; final int DELAY = 1000; String s; int nVal; // total value of neighbors int nfr = 323; int xToChange,yToChange; void setup() { // setup() is automatically run once // size(1200,800,P3D); size(1200,900); frameRate(40); for (i=0;i<324;i++) { s = "sequence/bee" + nf(i+1,3) + ".jpg"; // XS() pads with zeroes frame[i] = loadImage(s); } for (i=0;i= nfr) { beeCell[i][j].curFrame = 0; beeCell[i][j].tarFrame = 0; // neg # causes delay before starting to run again } */ image(frame[(beeCell[i][j].curFrame) % nfr],i*40 - (20 * (j%2)),j*30); // this line is more complicated than it would normally be // because I'm rigging it to do the hexagonal layout. } //end inner for } // end outer for } // end draw void mousePressed() { // This and mouseDragged are essentially identical. (xToChange,yToChange) is just (x,y) mouse position. xToChange = max(0,min((mouseX + 20*(j%2))/ 40,XS-1)); yToChange = max(0,min(mouseY / 30,YS-1)); // This next line is (the other) half of the central algorithm: set target frame forward by 100 when cell is clicked on beeCell[xToChange][yToChange].tarFrame = beeCell[xToChange][yToChange].tarFrame + 100; delay = 0; } void mouseDragged() { if (((mouseX + 20*(j%2))/ 40 != xToChange) || (mouseY / 30 != yToChange)) { // ie if we've dragged into a new cell xToChange = max(0,min((mouseX + 20*(j%2))/ 40,XS-1)); yToChange = max(0,min(mouseY / 30,YS-1)); beeCell[xToChange][yToChange].tarFrame = beeCell[xToChange][yToChange].tarFrame + 100; delay=0; } } class BeeCell { public int curFrame, tarFrame; BeeCell (int c) { curFrame = tarFrame = c; } } } // end class