Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PImage[] img;
- PImage mainImage;
- int x, y;
- int num=9, step = 1;
- void setup() {
- size(960,960);
- mainImage = loadImage("main.jpg");
- img = new PImage[num];
- for (int i=1; i<num; i++) {
- img[i] = loadImage(i+".jpg");
- }
- rectMode(CENTER);
- for (int x=step/2; x<width; x+= step) {
- for (int y=step/2; y<height; y+= step) {
- search(x, y);
- }
- }
- //filter(GRAY);
- }
- void draw() {
- }
- void search(int x, int y) {
- color best = color(0);
- float cost = 360;
- color baseColor = mainImage.get(x, y); // 90
- for (int i=1; i<num; i++) {
- color candidate = img[i].get(x,y); // 40
- float diff = abs(brightness(baseColor)-brightness(candidate)); // 50
- if (diff < cost) {
- best = candidate;
- cost = diff;
- }
- }
- fill(best);
- //stroke(best);
- noStroke();
- rect(x, y, step, step);
- }
- void keyPressed() {
- if (key == 's') save(random(1234)+".jpg");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement