Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- XML root, channel, item, description, title;
- XML[] items;
- String[] urls;
- PImage [] imgs;
- PImage a;
- int c, counter;
- boolean portrait;
- void setup() {
- size(1024, 1365);
- colorMode(HSB);
- a = loadImage("1.jpg"); // reference image
- portrait=a.width<a.height?true:false;
- importURLs();
- importResizeImages();
- drawStuff();
- }
- void draw() {
- }
- void keyPressed() {
- if (key == 's') save(random(344)+".png");
- }
- void importURLs() {
- //root = loadXML("https://www.pinterest.com/xeronimo/famous-people-monochrome.rss");
- root = loadXML("https://www.pinterest.com/xeronimo/those-bipeds-known-as-humans.rss");
- channel = root.getChild("channel");
- items = channel.getChildren("item");
- urls = new String[items.length];
- imgs = new PImage[items.length];
- for (int i=0; i<items.length; i++) {
- description = items[i].getChild("description");
- title = items[i].getChild("title");
- String d = description.getContent();
- String start = "https://";
- String end = ".jpg";
- int indexStart = d.indexOf(start);
- int indexEnd = d.indexOf(end);
- String descr = d.substring(indexStart, indexEnd+4);
- urls[i] = descr;
- }
- }
- void importResizeImages() {
- counter = -1;
- PImage temp = createImage(width, height, RGB);
- for (int i=0; i<urls.length; i++) {
- PImage b = loadImage(urls[i]);
- boolean portrait2=b.width<b.height?true:false;
- if (portrait2 == portrait) {
- counter++;
- if (portrait) {
- float ratio = (float) a.height/b.height;
- int w = int (b.width*ratio); // calculate b's new width in relation to a's height
- if (w<a.width) ratio *= (float) a.width/w; // if b's new width does not reach to the edge then calculate and add missing ratio
- int h = int (b.height*ratio); // calculate b's updated height
- w = int (b.width*ratio); // calculate b's updated, now fitting, width
- temp.copy(b, 0, 0, b.width, b.height, 0, 0, w, h);
- } else {
- float ratio = (float) a.width/b.width;
- int h = int (b.height*ratio);
- if (h<a.height) ratio *= (float) a.height/h;
- int w = int (b.width*ratio);
- h = int (b.height*ratio);
- temp.copy(b, 0, 0, b.width, b.height, 0, 0, w, h);
- }
- imgs[counter] = temp.get();
- }
- }
- }
- void drawStuff() {
- for (int x=0; x<width; x++) {
- for (int y=0; y<height; y++) {
- search(x, y);
- }
- }
- }
- void search(int x, int y) {
- color best = color(0);
- float cost = 360;
- color baseColor = a.get(x, y); // 90
- for (int i=0; i<counter; i++) {
- color candidate = imgs[i].get(x, y); // 40
- float diff = abs(brightness(baseColor)-brightness(candidate)); // 50
- if (diff < cost) {
- best = candidate;
- cost = diff;
- }
- }
- if (brightness(best)<50) best = color(hue(best), saturation(best), brightness(best)-25);
- stroke(best);
- point(x, y);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement