Created
February 7, 2015 13:07
-
-
Save hamoid/015f23936e7abf4f770d to your computer and use it in GitHub Desktop.
Processing function to get a random color set from ColourLovers
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
void setup() { | |
size(displayWidth, displayHeight); | |
int[] colors = getColorLove(); | |
println(colors); | |
noStroke(); | |
for(float x=0; x<width; x+=random(100)) { | |
fill(colors[(int)random(colors.length)]); | |
rect(x, 0, width, height); | |
} | |
} | |
int[] getColorLove() { | |
XML xml = loadXML("http://www.colourlovers.com/api/palettes/random"); | |
XML[] xcolors = xml.getChild("palette").getChild("colors").getChildren("hex"); | |
int[] colors = new int[xcolors.length]; | |
int i = 0; | |
for(XML c : xcolors) { | |
colors[i++] = unhex("FF" + c.getContent()); | |
} | |
return colors; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
No longer works, but here an alternative: https://github.com/vormplus/colorLib/blob/master/src/colorlib/webservices/ColourLovers.java