Advertisement
xeromino

collages

May 13th, 2016
302
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. PImage[] img;
  2. PImage mainImage;
  3. int x, y;
  4. int num=9, step = 1;
  5.  
  6. void setup() {
  7.   size(960,960);
  8.   mainImage = loadImage("main.jpg");
  9.   img = new PImage[num];
  10.   for (int i=1; i<num; i++) {
  11.     img[i] = loadImage(i+".jpg");
  12.   }
  13.   rectMode(CENTER);
  14.   for (int x=step/2; x<width; x+= step) {
  15.     for (int y=step/2; y<height; y+= step) {
  16.       search(x, y);
  17.     }
  18.   }
  19.   //filter(GRAY);
  20. }
  21.  
  22. void draw() {
  23. }
  24.  
  25. void search(int x, int y) {
  26.   color best = color(0);
  27.   float cost = 360;
  28.   color baseColor = mainImage.get(x, y); // 90
  29.   for (int i=1; i<num; i++) {
  30.     color candidate = img[i].get(x,y); // 40
  31.     float diff = abs(brightness(baseColor)-brightness(candidate)); // 50
  32.     if (diff < cost) {
  33.       best = candidate;
  34.       cost = diff;
  35.     }
  36.   }
  37.   fill(best);
  38.   //stroke(best);
  39.   noStroke();
  40.   rect(x, y, step, step);
  41. }
  42.  
  43. void keyPressed() {
  44.   if (key == 's') save(random(1234)+".jpg");
  45. }
Advertisement
Advertisement
Advertisement
RAW Paste Data Copied
Advertisement