hi,
i'm trying to work out the code for reproducing the cover of casey and ben's processing book. i've managed to do the setup of the sketch, and i've almost got the network points to connect to each other, based on evaluation of distance (if dist less than 100, then draw line between ellipses).
but i can't seem to get rid of that 'ArrayIndexOutOfBounds' error. any ideas? thanks in advance.
(i know the structure of the code could be much better, but this is one of my first 'extensive' codes.)
Code:// NETWORK DIAGRAM VERSION 2
// GLOBAL VARIABLES --------------------------------------------
int canvas = 900; // size of canvas (square)
int amount = 400; // amount of points on the screen
int minPtSize = 10; // min size of points/ellipse's
int maxPtSize = 100; // max size of points/ellipse's
int[] ptsX = new int[amount]; // declare + create new array
int[] ptsY = new int[amount]; // declare + create new array
// SETUP + DRAW RANDOM ELLIPSES --------------------------------
void setup() {
size(canvas, canvas);
smooth();
background(255);
noStroke();
strokeWeight(1.2);
fill(0, 170, 250, 40);
noLoop();
for (int i = 0; i < amount; i++) {
int x = rdmValue(0, canvas);
int y = rdmValue(0, canvas);
ptsX[i] = x;
ptsY[i] = y;
}
for (int i = 0; i < amount; i++) {
float r = random(minPtSize, maxPtSize);
ellipse(ptsX[i], ptsY[i], r, r);
stroke(0, 100);
fill(255);
ellipse(ptsX[i], ptsY[i], 4, 4);
noStroke();
fill(0, 170, 250, 40);
}
}
// DRAW --------------------------------------------------------
void draw() {
stroke(0, 100);
strokeWeight(0.5);
int count = 0;
for (int i = 0; i < amount; i++) {
for (int j = 0; j < amount; j++) {
if (dist(ptsX[count], ptsY[count], ptsX[i], ptsY[i]) < 100) {
line(ptsX[count], ptsY[count], ptsX[i], ptsY[i]);
}
count = count + 1;
}
}
}
// FUNCTION RANDOM VALUE ---------------------------------------
int rdmValue(float top, float bottom) {
int f = int(random(top, bottom));
return f;
}