Skip to content

Instantly share code, notes, and snippets.

@REAS
Last active September 10, 2018 21:26
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/491b9f6c4201d8dc5ba715d70d675d42 to your computer and use it in GitHub Desktop.
Save REAS/491b9f6c4201d8dc5ba715d70d675d42 to your computer and use it in GitHub Desktop.
Converts a JSON file with values from -1 to 1 into a line of gray rectangles
float[] latentspace;
String s = "RandGen_20180904-201026_00036"; // JSON file name
void setup() {
size(1000, 100);
loadData();
int w = 10;
int h = 100;
for (int i = 0; i < latentspace.length; i++) {
float g = map(latentspace[i], -1, 1, 0, 255);
fill(g);
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