Skip to content

Instantly share code, notes, and snippets.

@riebschlager
Created August 19, 2014 02:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save riebschlager/4780adcd1d79578990a5 to your computer and use it in GitHub Desktop.
Save riebschlager/4780adcd1d79578990a5 to your computer and use it in GitHub Desktop.
// http://labs.tineye.com/multicolr/rest/color_search/?limit=100&offset=0&colors[0]=73a1d2&colors[1]=d5c427&weights[0]=50&weights[1]=50
// http://img.tineye.com/flickr-images/?filepath=labs-flickr-public/images/3c/6872611445_3c927950b5_m.jpg&size=80
import java.util.*;
import java.net.*;
String baseUrl = "http://labs.tineye.com/multicolr/rest/color_search/?";
String baseImageUrl = "http://img.tineye.com/flickr-images/?filepath=labs-flickr-public/images/";
int pLimit = 200;
int pOffset = 0;
ArrayList<String> pColors = new ArrayList<String>();
ArrayList<Integer> pWeights = new ArrayList<Integer>();
ArrayList<String> imageUrls = new ArrayList<String>();
ArrayList<PImage> colorImages = new ArrayList<PImage>();
void setup() {
size(1920, 1080);
pColors.add("112F41");
pColors.add("FCB03C");
pWeights.add(floor(100 / pColors.size()));
pWeights.add(floor(100 / pColors.size()));
JSONObject tineye = loadJSONObject(baseUrl + generateParams());
JSONArray images = tineye.getJSONArray("result");
for (int i = 0; i < images.size (); i++) {
JSONObject obj = images.getJSONObject(i);
imageUrls.add(baseImageUrl + obj.getString("filepath"));
PImage tmpImage = loadImage(baseImageUrl + obj.getString("filepath"));
colorImages.add(tmpImage);
}
float sliceWidth = width / images.size();
float curX = 0;
int imgIndex = 0;
for (int i = 0; i < colorImages.size (); i ++) {
image(colorImages.get(i), sliceWidth * i, 0, sliceWidth, height);
}
Date d = new Date();
String filename = d.getTime() + ".tif";
save(filename);
}
String generateParams() {
String params = "limit=" + pLimit + "&offset=" + pOffset + "&";
for (int i = 0; i < pColors.size (); i++) {
params += "colors[" + i + "]=" + pColors.get(i);
if (i != pColors.size() - 1) {
params += "&";
}
}
params += "&";
for (int i = 0; i < pWeights.size (); i++) {
params += "weights[" + i + "]=" + pWeights.get(i);
if (i != pWeights.size()-1) {
params += "&";
}
}
return params;
}
void draw() {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment