程序运行效果:

Processing代码:

// gradiant varied by distance to mouse

int w = 5; // width of each rectangle
int y; 

void setup(){
  size(640, 480);
  y = height/2;
  colorMode(RGB, width);
  rectMode(CENTER);
  noStroke();
}

void draw(){
  for(int x = w/2; x<width-w/2; x+=w){
    int dx = abs(mouseX-x);  // distance to mouse
    fill(dx);
    rect(x, y, w, height);
  }
}