Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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