Skip to content

Instantly share code, notes, and snippets.

@REAS
Created September 11, 2018 20:47
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 REAS/4aa15dd101d5b3d781a99f105880f6ab to your computer and use it in GitHub Desktop.
Save REAS/4aa15dd101d5b3d781a99f105880f6ab to your computer and use it in GitHub Desktop.
Converts a JSON file with values from -1 to 1 into a line of rectangles moving through hues from orange to blue
float[] latentspace;
String s = "RandGen_20180904-201026_00036"; // JSON file name
void setup() {
size(1000, 100);
colorMode(HSB, 360, 100, 100);
loadData();
int w = 10;
int h = 100;
for (int i = 0; i < latentspace.length; i++) {
int orange = 25;
int blue = 210;
float c = map(latentspace[i], -1, 1, orange, blue);
fill(c, 70, 80);
noStroke();
rect(i*w, 0, w, h);
}
saveFrame(s + ".png");
println("finished...");
exit();
}
void loadData() {
JSONArray data = loadJSONArray(s + ".json");
println(data.size());
latentspace = new float[data.size()];
for (int i = 0; i < latentspace.length; i++) {
latentspace[i] = data.getFloat(i);
println(latentspace[i]);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment