Skip to content

Instantly share code, notes, and snippets.

@gncgnc
Last active September 23, 2016 00:29
Show Gist options
  • Save gncgnc/80a680662c3da00067a7a700e410b2e2 to your computer and use it in GitHub Desktop.
Save gncgnc/80a680662c3da00067a7a700e410b2e2 to your computer and use it in GitHub Desktop.
Getting random color palettes from an API, in Processing. Here's the API page: http://savemypalette.com/api/#random
color[] colors;
void getColorPalette(){
try {
String[] strs = loadStrings("http://savemypalette.com/api/random/palettes/");
saveStrings("colorData", strs);
JSONObject json = loadJSONObject("colorData");
JSONArray cs = json.getJSONArray("colors");
String[] colorStrings = cs.getStringArray();
colors = new color[colorStrings.length];
for(int i=0; i<colors.length; i++){
colors[i] = unhex("FF"+colorStrings[i]); // colors loaded
//testing colors
fill(colors[i]);
ellipse(width*(.1*i+0.3),height/2,width*.1,width*.1);
}
} catch (Exception e) {
println("Failed to get data.");
println("e: "+e);
}
}
void setup(){
size(100,75);
background(0);
getColorPalette();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment