// Horseys I (single horsey, footprint mode) // Jo Wilson, May 2010 // http://www.pixelbrain.me.uk // written in Processing 1.1 int dim = 400; // screen dimensions (square) int x, y; void setup() { size(dim,dim,P3D); background(0); frameRate(1000); //choose starting point x = int(random(0.25*dim,0.75*dim)); y = int(random(0.25*dim,0.75*dim)); } void draw() { moveHorsey(); // choose colour based on position (produces nice gradient) color c = color(200*(dim-x)/dim, 50*(dim-y)/dim, 200*x/dim); set(x, y, c); } // If horsey is inside the drawing area, choose which knight's move it will make. void moveHorsey() { if ((x > 0) && (x < dim) && (y > 0) && (y < dim)) { float r = random(0,200); if (r < 25) { x = x + 1; y = y + 2; } else if (r < 50) { x = x + 1; y = y - 2; } else if (r < 75) { x = x + 2; y = y + 1; } else if (r < 100) { x = x + 2; y = y - 1; } else if (r < 125) { x = x - 1; y = y + 2; } else if (r < 150) { x = x - 1; y = y - 2; } else if (r < 175) { x = x - 2; y = y + 1; } else if (r < 200) { x = x - 2; y = y - 1; } } // If horsey has escaped, save picture and exit. //else { //save("Horseys1_"+dim+".png"); //exit(); //} } void mouseClicked() { reset(); } // clear drawing canvas and re-initialise x and y void reset() { background(0); x = int(random(0.25*dim,0.75*dim)); y = int(random(0.25*dim,0.75*dim)); }