交互:用到鼠标的实时距离来定义渐变色

程序运行效果:

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);
  }
}
原文地址:https://www.cnblogs.com/xxfcz/p/13881549.html