Complex gradient loop

here is an example

(which is just made up and not accurate)





PVector[] listPV = {
  new PVector (0, 0),
  new PVector (0, 200),
  new PVector (550, 400),
  new PVector (50, 500),
  new PVector (600, 800)
};

color[] listColor = {
  color (200, 255, 255),
  color (0, 0, 0),
  color (255, 200, 200),
  color (255, 0, 255),
  color (255, 0, 0)
};

void setup() {
  size(600, 800);

  // PVector point = new PVector(0, 0);
  // points.add(point);
}

void draw() {
  background(255);

  for (int i = 0; i < height; i++) {

    //PVector pointMy = list[i];

    float x1 = 20;
    float y1 = 0;

    color a = getCol (x1, i); // color(200, 255, 255);
    fill(a);
    noStroke();
    rect(x1, i, 5, 5);
  }

  int i2=0;
  for (PVector pv : listPV) {
    fill(listColor[i2]);
    rect(pv.x, pv.y, 6, 6);
    i2++;
  }

  noLoop();
}

color getCol(float x1, float y1) {

  color c1=0;
  int i2=0;

  for (PVector pv : listPV) {
    float f1 = listPV[i2].dist(new PVector(x1, y1));
    float amt = map(f1, 0, 600, 1, 0) ;
    c1 = lerpColor ( c1, listColor[i2], amt) ;
    i2++;
  }

  return c1;
}

1 Like