Daily Creative Coding

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

画像から点描画をつくる

f:id:aa_debdeb:20151022223738j:plain
/**
* Pointilism Image
*  
* @author aa_debdeb
* @date 2015/10/26
*/

void setup(){
  size(512, 512);
  PImage image = loadImage("lena.jpg");
  image(image, 0, 0);
  loadPixels();
  color[][] colors = new color[width][height];
  for(int x = 0; x < width; x++){
    for(int y = 0; y < height; y++){
      colors[x][y] = pixels[y * width + x];
    }
  }
  background(255);
  noStroke();
  for(int i = 0; i < 100000; i++){
    int x = int(random(width));
    int y = int(random(height));
    fill(colors[x][y]);
    ellipse(x + map(random(1), 0, 1, -0.5, 0.5),
            y + map(random(1), 0, 1, -0.5, 0.5),
            7, 7);
  }
}