Hey eyeryone.
So this is my first post. I’ve only started with processing.
We got the task to make a grid of 2D Primitives which can be altered through changing the size() or number of elements.
I figured that part out.
But we should also change the color of each element gradually.
I wrote some code that I think should work. But it doesn’t.
size(400, 400);
background(255,255,255);
noStroke();
//variables
//shapes
int num; //number of shapes
num = 4;
int totN; //numb*numb //total number of 2D primitives
totN = num*num;
int br; //width of shapes
br = width/num;
int hoehe;
hoehe = height/num;
//content
colorMode(HSB, totN, 100, 100);
for (float x=0; x<num; x=x+1) {
>>for (float y=0; y<num; y=y+1) {
>>>for (float hue=0; hue<totN; hue=hue+1){
>>>>pushMatrix();
>>>>translate(x*br, y*hoehe);
>>>>fill(hue, 50, 80); //Farbe mit festgelegter Helligkeit
>>>>ellipse(0.5*br, 0.5*hoehe, br, hoehe);
>>>>popMatrix();
>>}
>}
}
This is what I am trying to archieve (I did that one without a loop).
I used totN = num*num because I want the objects to have the full range of color not matter how I change num.
The problem was using the third loop I think.
This is my final code.
size(500, 500);
background(255);
int num, hue, br, hoehe, count;
num = 10;
br = width/num;
hoehe = height/num;
hue = num*num;
count =1;
colorMode(HSB, hue, 100, 100, 100);
noStroke();
for (float x = 0; x < num; x=x+1) {
for (float y = 0; y < num; y=y+1) {
hue -= count;
pushMatrix();
translate(y*hoehe, x*br);
fill(hue, 100, 80, 85);
ellipse(0.5*br, 0.5*hoehe, br, hoehe);
popMatrix();
}
}