float scaleRange, old_scaleRange, xb, yb;
old_scaleRange = scaleRange;
levels = round( ( xb / 800 ) * 8 );
scaleRange = mouseY * 10 / ( 8 * 5 );
scaleRange = scaleRange / 1000;
if ((old_levels != levels) || (old_scaleRange != scaleRange))
oldB[0][0] = new Cell(100, 100);
oldB[0][1] = new Cell(100, 700);
oldB[1][0] = new Cell(700, 100);
oldB[1][1] = new Cell(700, 800);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if (((i%2) == 0) && ((j%2) == 0)) {
newB[i][j] = new Cell(oldB[ii][jj].x, oldB[ii][jj].y);
else if (((i%2) == 0) && ((j%2) == 1)) {
float x=( oldB[ii][jj].x + oldB[ii][jj+1].x ) / 2;
float y=( oldB[ii][jj].y + oldB[ii][jj+1].y ) / 2;
float d= sqrt( sq(oldB[ii][jj].x - oldB[ii][jj+1].x) + sq(oldB[ii][jj].y - oldB[ii][jj+1].y) );
float rng = d*scaleRange;
float xu = random(-rng, rng);
float yu = random(-rng, rng);
newB[i][j] = new Cell(x+xu, y+yu);
else if (((i%2) == 1) && ((j%2) == 0)) {
float x=( oldB[ii][jj].x + oldB[ii+1][jj].x ) / 2;
float y=( oldB[ii][jj].y + oldB[ii+1][jj].y ) / 2;
float d= sqrt( sq(oldB[ii][jj].x - oldB[ii+1][jj].x) + sq(oldB[ii][jj].y - oldB[ii+1][jj].y) );
float rng = d*scaleRange;
float xu = random(-rng, rng);
float yu = random(-rng, rng);
newB[i][j] = new Cell(x+xu, y+yu);
else if (((i%2) == 1) && ((j%2) == 1)) {
float x=( oldB[ii][jj].x + oldB[ii+1][jj+1].x ) / 2;
float y=( oldB[ii][jj].y + oldB[ii+1][jj+1].y ) / 2;
float d= sqrt( sq(oldB[ii][jj].x - oldB[ii+1][jj+1].x) + sq(oldB[ii][jj].y - oldB[ii+1][jj+1].y) );
float rng = d * scaleRange * 0.7;
float xu = random(-rng, rng);
float yu = random(-rng, rng);
newB[i][j] = new Cell(x+xu, y+yu);
for (int i=0; i<n; i++) {
for (int j=0; j<n; j++) {
if ((i<n-1) && (j<n-1)) {
line( oldB[i][j].x, oldB[i][j].y, oldB[i][j+1].x, oldB[i][j+1].y);
line( oldB[i][j].x, oldB[i][j].y, oldB[i+1][j].x, oldB[i+1][j].y);
else if ((i == (n-1)) && (j<n-1)) {
line( oldB[i][j].x, oldB[i][j].y, oldB[i][j+1].x, oldB[i][j+1].y);
else if ((i<n-1) && (j == (n-1))) {
line( oldB[i][j].x, oldB[i][j].y, oldB[i+1][j].x, oldB[i+1][j].y);
old_scaleRange = scaleRange;
Cell(float tempX, float tempY) {