/** *

Based of blackHole, written by John Beech - 2005|06|22.

*

This applet accessed an array from its centre outwards, spiralling around clockwise until there are no elements left.
* The method nextHit() relies on several variables to keep track of where it is in the array, including the width/height of the array * theta, and a check in the actual array to see if data has been set already.

*

Next hit will continue to run until all the array elements are hit, calculated roughly by aryWidth*1.5 and aryHeight*1.5. * When nextHit exceeds this boundary it will return false. When false is detected, the array turns blue to mark completion. * This bit of the process isn't very efficient - I can't think of a way to make it efficient, but it works, and thats what matters.

*/ // declare vars float theta; int x, y; int aryWidth, aryHeight; int arySpacing; boolean checkAry[][]; boolean finished; void setup() { // set up scene size(300, 300); background(255); framerate(25); // set vars aryWidth = 21; aryHeight = 21; if(aryWidth >= aryHeight) arySpacing = (width-20)/aryWidth; else arySpacing = (height-20)/aryHeight; checkAry = new boolean[aryWidth][aryHeight]; finished = false; } void draw() { // move grid to centre of applet translate(width/2, height/2); // centre grid based on ary's width/height translate(round((float)-aryWidth/2*arySpacing), round((float)-aryHeight/2*arySpacing)); // update array if(nextHit()) { checkAry[x][y] = true; } else { finished = true; } // draw grid stroke(153); //rectMode(CORNERS); for(int i=0; i= 0 && x < aryWidth && y >= 0 && y < aryHeight) { if(checkAry[x][y]) { // give theta a boost if stuck on black incr *= 1.04; } else { return true; } } else { // can't perform check, probably a good idea to increment incr *= 1.04; } } while(x < aryWidth*1.5 && y < aryWidth*1.5); return false; }