Hello,
I have the following code, you have to get a canvas with two lines of numbers from the two arrays. The top row must contain the values of the top_array array and the bottom row must contain the values of the bottom_array. Other than that, I want to compare the positions of the two arrays to paint, for each position, the largest value in green and the smallest value in red. If both are the same, you will need to paint them white. The problem is, I don’t know how to do it.
Could someone help me? Thanks
int dimension_arrays = 10;
int[] top_array = new int[dimension_arrays];
int[] bottom_array = new int[dimension_arrays];
int distance = 0;
PFont f;
void setup() {
size(600, 300);
distance = width/dimension_arrays;
for (int i = 0; i < dimension_arrays; i++) {
top_array[i] = int(random(0, 100));
bottom_array[i] = int(random(0, 100));
}
}
void draw() {
background(0, 100, 130);
f = createFont("Arial", 28, true);
textFont(f, 28);
for (int i = 0; i < top_array.length; i++){
text(top_array[i], width/2, height/3);
for (int j= 0; j < bottom_array.length; j++){
text(bottom_array[j], width/2, height-height/3);
if (top_array[i] > bottom_array[j]) {
fill(0,255,0);
}
else if (bottom_array[j]>top_array[i]){
fill(0,255,0);
}
else if(top_array[i]<bottom_array[j]){
fill(255,0,0);
}
else if (bottom_array[j]<top_array[i]){
fill(255,0,0);
}
else if(top_array[i]==bottom_array[j]){
fill(0);
}
}
}