Created
January 19, 2018 08:03
-
-
Save jnsdbr/f4ebbaae7273bd17cd6aaf4ba3d8a583 to your computer and use it in GitHub Desktop.
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
PFont font; | |
void setup() | |
{ | |
size(500, 600); | |
background(200); | |
font = createFont("Courier", 20); | |
textFont(font); | |
ArrayList<Palette> palettes = getTopPalettes(); | |
int y = 20; | |
for (Palette p: palettes) | |
{ | |
for (int i = 0; i < p.colorCount; i++) | |
{ | |
fill(p.colors[i]); | |
ellipse((i + 1) * 20, y, 20, 20); | |
} | |
text(p.title, 120, y + 7); | |
y += 25; | |
} | |
} | |
ArrayList<Palette> getTopPalettes() | |
{ | |
ArrayList<Palette> palettes = new ArrayList<Palette>(); | |
JSONArray jsonPalettes = loadJSONArray("http://www.colourlovers.com/api/palettes/top?format=json"); | |
for (int i = 0; i < jsonPalettes.size(); i++) | |
{ | |
JSONObject p = jsonPalettes.getJSONObject(i); | |
JSONArray extractedColors = p.getJSONArray("colors"); | |
int[] colors = new int[extractedColors.size()]; | |
for (int j = 0; j < extractedColors.size(); j++) | |
{ | |
colors[j] = unhex("FF" + extractedColors.getString(j)); | |
} | |
Palette palette = new Palette(colors, p.getString("title")); | |
palettes.add(palette); | |
} | |
return palettes; | |
} |
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
public class Palette | |
{ | |
public int[] colors; | |
public int colorCount; | |
public String title; | |
public Palette(int[] colors, String title) | |
{ | |
this.colors = colors; | |
this.colorCount = colors.length; | |
this.title = title; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment