float inc = 0.1; // SIZE oF NOISE
float scl = 10; // SCALE of GRID
float r;
void setup() {
size(500,500);
noSmooth(); // Draws all geometry and fonts with jagged edges
strokeCap(PROJECT); // appearance of the points: ROUND - circle, PROJECT - square
strokeWeight(5); // thicknes of the points
}
void draw() {
float yoff = 0;
for (float y = 0; y < height; y++) {
float xoff = 0;
for (float x = 0; x < width; x++) {
float r = noise(xoff, yoff) * 255;
xoff += inc;
//stroke(r);
point(x * scl, y * scl);
}
yoff += inc;
}
stroke(r); // <----------- I need it here for further development
println(r);
}
Go through your code and address all the scope issues; there may be other logical errors as well.
I showed you one obvious example.
There may be others to sort out.
I just took one quick look… I will leave this with you to sort out.
You can store ALL colors from r into an array (1D or 2D array, see tutorials: Tutorials / Processing.org).
In my code below the array is listColors2. (listColors is only temporary)
The scope
The scope of r is only INSIDE the for-loop because of this line:
float r = noise(xoff, yoff) * 255;
you can use r after the for loop but then you would use only the last value of r (not all of them like in an array). Would that be enough for you?
To achieve this say float r;before the for loop (or even before setup()) and say r = noise(xoff, yoff) * 255; within the for-loop (without repeating the word “float”).
before the for loop means: scope = function
before setup() means: scope = entire sketch
inside the for-loop: scope = inside the for-loop
Explained here:
The colors
By the way, data type color is in fact int.
so you can say
int r = 23344;
stroke(r); - for point or line
fill(r); - for ellipses, rect, cube, sphere (for sphere() together with noStroke();)…
or
color(44); // gray or
color(255,2,2); // which is red.
Chrisir
Full code with array
float inc = 0.1; // SIZE of NOISE
float scl = 10; // SCALE of GRID
float r;
color[] listColors2;
void setup() {
size(500, 500);
noSmooth(); // Draws all geometry and fonts with jagged edges
strokeCap(PROJECT); // appearance of the points: ROUND - circle, PROJECT - square
strokeWeight(5); // thickness of the points
}//
void draw() {
IntList listColors = new IntList();
float yoff = 0;
for (float y = 0; y < height; y++) {
float xoff = 0;
for (float x = 0; x < width; x++) {
float r = noise(xoff, yoff) * 255;
xoff += inc;
stroke(r);
listColors.append(int(r));
point(x * scl, y * scl);
}
yoff += inc;
}
// stroke(r); // <----------- I need it here for further development
listColors2 = listColors.array();
for (color c : listColors2) {
println(c);
}
//
}//
//