size(300, 300);
int[]data={50, 100, 30, 120, 40, 70, 150};
int max=data[0];
int min=data[0];
for (int i=0; i<data.length; i++) {
fill(255);
rect(10+15*i, 10, 10, data[i]);
if(max<data[i]) {
max=data[i];
fill(255, 0, 0);
rect(10+15*i, 10, 10, max);
}
if ( min>data[i]) {
min=data[i];
fill(0, 0, 255);
rect(10+15*i, 10, 10, min);
}
}
1 Like
You need to run the entire for loop without drawing to set min and max
Then run the 2nd for loop and set fill accordingly to max and min and draw the rect after setting fill
3 Likes
yes, like
size(300, 300);
int[]data={50, 100, 30, 120, 40, 70, 150};
int max=-1000, min=1000;
for (int i=0; i<data.length; i++) { // first min max run
if ( max < data[i]) max = data[i];
if ( min > data[i]) min = data[i];
}
for (int i=0; i<data.length; i++) { // draw run
fill(255); // make color
if ( max == data[i] ) fill(255, 0, 0);
if ( min == data[i] ) fill(0, 0, 255);
rect(10+15*i, 10, 10, data[i]); // draw
}
2 Likes
Thank you Chrisir! I solved the problem!
Thank you so much! kll !
I solved the problem!
1 Like