Last active
September 23, 2016 00:29
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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