Hi,
I'm quite new to Processing and programming and have come across a problem that I was hoping someone may be kind enough to help me with.
I'm using an embedded "for" loop to create a matrix of circles which works o.k in the following example:
Code:
size (500,500);
stroke(0);
smooth();
int f=0;
int direction=1;
for(int x=25; x<500; x=x+50){
for(int y=25; y<500; y=y+50){
fill(f=f+25*direction);
ellipse (x,y,20,20);
if (f>=255||f<=0){
direction=direction*-1;
}}}
However, the next stage of the experiment fails when I attempt to make the distance between the centre point of the ellipses decrease by introducing a new variable into the loop as follows:
Code:
size (500,500);
stroke(0);
smooth();
int f=0;
int g=0;
int direction=1;
for(int x=25; x<500; x=x+50-g){
for(int y=25; y<500; y=y+50-g){
fill(f=f+25*direction);
ellipse (x,y,20,20);
g=g+5;
if (f>=255||f<=0){
direction=direction*-1;
}}}
Running this code causes Processing to freeze, without any error message. I'm guessing that introducing another variable into the loop causes some sort of badness that I don't understand.
If someone could explain or offer a more elegant( and functional) solution, I'd appreciate it.