REALLY basic functions problem

this

 if (MIN<60) {
    fill(255);
  } else {
    fill(0);
  }

is changing the color of the text (not of the ellipse) - which is ok

My version

  • intially MIN can be 0, it gets overwritten; MIN_local must have a big value initially though.

  • passing a as a parameter now. Therefore it can be moved into setup() and not be of global scope anymore.

  • using textAlign(CENTER, CENTER); and text(MIN, width/2, height/2);

Chrisir

int MIN = 0;

void setup() {
  size(450, 450);

  int[] a = new int [50];
  for (int i=0; i < a.length; i++) {
    a[i] = (int) random (255);
    print(a[i]+", ");
  }
  MIN = getArrayMin(a);
}//func

void draw() {
  // show ellipse
  fill (MIN);
  ellipse(width/2, height/2, width/2, height/2);

  // show text
  if (MIN<60) {
    fill(255);
  } else {
    fill(0);
  }
  textSize(width/4);
  textAlign(CENTER, CENTER); 
  text(MIN, width/2, height/2);
}//func

// ------------------------------------------------------

int getArrayMin(int[] a) {
  int MIN_local=11000;
  for (int i=0; i<a.length; i++) {
    if (a[i]< MIN_local) {
      MIN_local = a[i];
    }
  }
  return MIN_local;
}//func
1 Like