-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathGoogle_Quick_Draw.pde
51 lines (45 loc) · 1.13 KB
/
Google_Quick_Draw.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
* Quick, Draw! The Data with Processing
* by Federico Pepe
* 23.05.2017
*
* Quick, Draw! Dataset by Google
* https://github.com/googlecreativelab/quickdraw-dataset
*/
BufferedReader reader;
String line;
JSONObject json;
void setup() {
size(256, 256);
reader = createReader("full-simplified-anvil.ndjson");
}
void draw() {
}
void mousePressed() {
background(127);
try {
line = reader.readLine();
json = parseJSONObject(line);
JSONArray drawing = json.getJSONArray("drawing");
for (int i = 0; i < drawing.size(); i++) {
JSONArray var = drawing.getJSONArray(i);
for (int j = 0; j < var.size(); j += var.size()) {
beginShape();
for (int z = 0; z < var.getJSONArray(j).size(); z++) {
vertex(var.getJSONArray(j).getInt(z), var.getJSONArray(j+1).getInt(z));
}
endShape(CLOSE);
}
}
}
catch (IOException e) {
e.printStackTrace();
line = null;
}
// As find in BufferedReader's reference
// https://processing.org/reference/BufferedReader.html
if (line == null) {
// Stop reading because of an error or file is empty
noLoop();
}
}