Daily Creative Coding

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

カメラから取得したイメージを水彩画風モザイクにする

f:id:aa_debdeb:20160517002303j:plain
/**
* watercolor mosaic from camera image
* 
* @author aa_debdeb
* @date 2016/05/25
*/

import processing.video.*;

Capture camera;
ArrayList<Point> points;

void setup(){
  size(640, 480);
  camera = new Capture(this, width, height);
  camera.start();
  points = new ArrayList<Point>();
  for(int i = 0; i < 100; i++){
    points.add(new Point());
  }
  noStroke();
}

void draw(){
  colorMode(RGB, 255);
  background(255);
  colorMode(HSB, 360, 100, 100);
  camera.loadPixels();
  for(Point p: points){
    color c = camera.pixels[int(p.pos.y) * width + int(p.pos.x)];
    fill(hue(c), 100, 100, 10);
    ellipse(p.pos.x, p.pos.y, p.diameter, p.diameter);
  }
  points.remove(0);
  points.add(new Point());
}

void captureEvent(Capture camera){
  camera.read();
}

class Point{
  PVector pos;
  float diameter;
  
  Point(){
    pos = new PVector(random(width), random(height));
    diameter = random(300, 800);
  } 
  
}