//chemotaxis game //authorL Orkun Soyer //import processing.video.*; bug oss; int xsize = 700; int ysize = 700; float bugspeed = 0.5; float decision = 0.5; float pTumbleExit = 0.9; float pTumbleEntry = 0.35; float grid[][] = new float[xsize][ysize]; float gridNext[][] = new float[xsize][ysize]; float diffCoeff = 0.01; float deltaT = 0.01; float deltaXsq = 0.1; void setup() { size(700, 700); //This command makes a board. // colorMode(RGB,10);//This command makes the colormode. // background(0,0,9);//What color the backround is. oss = new bug(13,5.0,xsize/2,ysize/2,45.0);//creats a object from class bug called oss with given properties. for(int i=0;i= xsize) {foodXend = 0;} foodYstart = mouseY-10; if (foodYstart < 0) {foodYstart = ysize-1;} foodYend = mouseY + 10; if (foodYend >= ysize) {foodYend = 0;} dropFood = true; } if (dropFood) { for(int i=foodXstart;ixsize) bugposX = 0; if (bugposX<0) bugposX = xsize; if (bugposY>ysize) bugposY = 0; if (bugposY<0) bugposY = ysize; } void tumble() { bugangle = bugangle + 1*random(0,16); } void display() { pushMatrix(); translate(bugposX,bugposY); rotate(radians(bugangle)); rect(0,0,bugwidth,bugheight); triangle(0,bugheight,0,0,4,bugheight/2); popMatrix(); } } // diffusion of chemical void diffusion() { float multiplier = diffCoeff*deltaT/deltaXsq; int qx=0, qy=0, wx=0, ex=0; int ax=0, ay=0, dx=0; int zx=0, zy=0, xx=0, cx=0; for(int i=0;i= ysize) {qy = 0;} wx = i; ex = i+1; if (ex >= xsize) {ex = 0;} ax = i-1; if (ax < 0) {ax = xsize-1;} ay = j; dx = i+1; if (dx >= xsize) {dx = 0;} zx = i-1; if (zx < 0) {zx = xsize-1;} zy = j-1; if (zy < 0) {zy = ysize-1;} xx = i; cx = i+1; if (cx >= xsize) {cx = 0;} gridNext[i][j] = grid[i][j]-multiplier*grid[i][j]+(multiplier*grid[qx][qy]+multiplier*grid[wx][qy]+multiplier*grid[ex][qy]+multiplier*grid[ax][ay]+multiplier*grid[dx][ay]+multiplier*grid[zx][zy]+multiplier*grid[xx][zy]+multiplier*grid[cx][zy]); if (gridNext[i][j] < 0.0) {gridNext[i][j] = 0.0;} } } float temp[][] = grid; grid = gridNext; gridNext = temp; }