The main problem you're having is that you're trying to reference 'width' before setup has run and that's a really bad idea since IIRC it doesn't get set till after... Anyway the answer is simple enough: You can declare the variable before setup so it's 'global' (i.e. can be referenced in draw()) and assign it a value in setup after size() has been called:
Code:int[] als = {10,40,60,80,90,140 };
//int s = second();
// declare the variable as global
int largo;
void setup() {
// size() should *always* come first:
size(800,800);
// assign the value to the variable
largo = width/10;
smooth();
frameRate(2);
}
void draw(){
background (255);
for (int x = largo/2; x < width; x+= width/10-largo/2){
for (int y = largo/2; y < height; y+= width/10-largo/2) {
noStroke();
fill (0,als[ int( random (6) ) ] ) ;
ellipse(x,y,largo,largo);
}
}
}
Mind you I think you may still have problems with some values as it looks like your draw loop contains a few magic number - e.g. width/10
Replacing the 10 with a variable, both in the assignment of largo and in those width/10 references, seems to work regardless of the value used (though it gets a bit slow if you set it too high):
Code:int[] als = {10,40,60,80,90,140 };
//int s = second();
// declare the variable as global
int largo;
int divisor = 30;
void setup() {
// size() should *always* come first:
size(800,800);
// assign the value to the variable
largo = width/divisor;
smooth();
frameRate(2);
}
void draw(){
background (255);
for (int x = largo/2; x < width; x+= width/divisor-largo/2){
for (int y = largo/2; y < height; y+= width/divisor-largo/2) {
noStroke();
fill (0,als[ int( random (6) ) ] ) ;
ellipse(x,y,largo,largo);
}
}
}