Daily Creative Coding

元「30 min. Processing」。毎日、Creative Codingします。

補色

/**
* complementary color
*
* @author aa_debdeb
* @date 2016/03/30
*
*/

ArrayList<PVector> ps1;
ArrayList<PVector> ps2;

color bgc, pc1, pc2;

void setup(){
  size(640, 480);
  noStroke();
  colorMode(HSB, 360, 100, 100);
  
  ps1 = new ArrayList<PVector>();
  for(int i = 0; i < 70; i++){
    ps1.add(new PVector(random(width), random(height)));
  }
  
  ps2 = new ArrayList<PVector>();
  for(int i = 0; i < 30; i++){
    ps2.add(new PVector(random(width), random(height)));
  } 
  
  setColor();
}

void mousePressed(){
  setColor();
}

void setColor(){
  bgc = color(random(360), 0, random(100));
  float hue1 = random(360);
  float hue2 = hue1 >= 180 ? hue1 - 180 : hue1 + 180;
  float sat = random(100);
  float bri = random(70, 100);
  pc1 = color(hue1, sat, bri);
  pc2 = color(hue2, sat, bri);
}

void draw(){
  background(bgc);
  
  PVector mouse = new PVector(mouseX, mouseY);
  PVector center = new PVector(width / 2, height / 2);
  PVector vel = PVector.sub(mouse, center);
  vel.limit(3);
 
  fill(pc2);
  for(PVector p: ps2){
    ellipse(p.x, p.y, 15, 15);
    p.add(vel);
    border(p);
  }
  
  fill(pc1);
  for(PVector p: ps1){
    ellipse(p.x, p.y, 30, 30);
    p.add(PVector.mult(vel, -1));
    border(p);
  }
 
}

void border(PVector p){
  if(p.x < 0){
    p.x += width;
  }
  if(p.x >= width){
    p.x -= width;
  }
  if(p.y < 0){
    p.y += height;
  }
  if(p.y >= height){
    p.y -= height;
  }
}