Skip to content

Commit 10057a2

Browse files
committed
Refactor code
1 parent 074bb66 commit 10057a2

29 files changed

Lines changed: 15806 additions & 1046 deletions

File tree

cache/linux-x64/Processing.o

51.2 KB
Binary file not shown.
Binary file not shown.
Binary file not shown.
Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,44 @@
11
{
2-
"bubbles": [
3-
{ "position": { "x": 160, "y": 103 }, "diameter": 43.19, "label": "Happy" },
4-
{ "position": { "x": 372, "y": 137 }, "diameter": 52.42, "label": "Sad" },
5-
{ "position": { "x": 273, "y": 235 }, "diameter": 61.80, "label": "Meh" }
6-
]
7-
}
2+
"bubbles": [
3+
{
4+
"diameter": 43.19,
5+
"label": "Happy",
6+
"position": {
7+
"x": 160,
8+
"y": 103
9+
}
10+
},
11+
{
12+
"diameter": 52.42,
13+
"label": "Sad",
14+
"position": {
15+
"x": 372,
16+
"y": 137
17+
}
18+
},
19+
{
20+
"diameter": 61.8,
21+
"label": "Meh",
22+
"position": {
23+
"x": 273,
24+
"y": 235
25+
}
26+
},
27+
{
28+
"diameter": 72.5889,
29+
"label": "New label",
30+
"position": {
31+
"x": 459,
32+
"y": 198
33+
}
34+
},
35+
{
36+
"diameter": 45.4191,
37+
"label": "New label",
38+
"position": {
39+
"x": 362,
40+
"y": 243
41+
}
42+
}
43+
]
44+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* LoadFile 1
3+
*
4+
* Loads a text file that contains two numbers separated by a tab.
5+
* A new pair of numbers is loaded each frame and used to draw a point.
6+
* Translated to C++ Mode.
7+
*/
8+
9+
std::vector<std::string> lines;
10+
int index = 0;
11+
12+
void setup() {
13+
size(640, 360);
14+
background(0);
15+
stroke(255);
16+
frameRate(12);
17+
lines = loadStrings("data/positions.txt");
18+
}
19+
20+
void draw() {
21+
if (index < (int)lines.size()) {
22+
std::vector<std::string> pieces = split(lines[index], '\t');
23+
if (pieces.size() == 2) {
24+
float x = map(toFloat(pieces[0]), 0, 100, 0, width);
25+
float y = map(toFloat(pieces[1]), 0, 100, 0, height);
26+
point(x, y);
27+
}
28+
index++;
29+
}
30+
}
Lines changed: 206 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
1+
70 35
2+
69 35
3+
68 39
4+
67 42
5+
66 47
6+
64 51
7+
64 54
8+
63 57
9+
60 60
10+
58 64
11+
51 69
12+
48 72
13+
44 73
14+
39 75
15+
35 75
16+
30 75
17+
25 75
18+
21 75
19+
17 73
20+
13 69
21+
12 66
22+
11 61
23+
11 57
24+
10 49
25+
10 45
26+
10 38
27+
12 32
28+
13 29
29+
16 23
30+
20 19
31+
24 16
32+
27 15
33+
31 13
34+
33 13
35+
37 13
36+
40 15
37+
42 16
38+
45 19
39+
46 21
40+
47 24
41+
48 26
42+
48 29
43+
48 33
44+
47 39
45+
43 45
46+
42 47
47+
38 50
48+
35 51
49+
32 51
50+
30 51
51+
27 50
52+
27 50
53+
26 46
54+
26 41
55+
29 36
56+
30 34
57+
31 33
58+
31 33
59+
32 33
60+
33 33
61+
34 33
62+
34 33
63+
35 33
64+
37 33
65+
39 33
66+
42 32
67+
44 31
68+
46 29
69+
48 29
70+
49 27
71+
52 24
72+
53 23
73+
57 19
74+
61 16
75+
63 14
76+
67 13
77+
69 12
78+
69 12
79+
77 11
80+
77 11
81+
80 11
82+
86 16
83+
90 21
84+
93 25
85+
95 29
86+
95 32
87+
95 33
88+
95 37
89+
94 41
90+
93 44
91+
92 46
92+
91 49
93+
89 51
94+
87 55
95+
85 59
96+
82 62
97+
80 64
98+
79 67
99+
77 69
100+
74 71
101+
68 72
102+
65 73
103+
63 73
104+
62 73
105+
60 72
106+
58 69
107+
57 67
108+
57 66
109+
56 60
110+
56 56
111+
56 54
112+
58 49
113+
60 47
114+
62 47
115+
63 47
116+
67 48
117+
70 52
118+
73 55
119+
74 57
120+
74 58
121+
74 60
122+
74 62
123+
73 65
124+
70 68
125+
67 69
126+
65 70
127+
63 70
128+
62 70
129+
60 68
130+
57 65
131+
55 64
132+
50 62
133+
46 61
134+
40 60
135+
38 60
136+
36 60
137+
32 61
138+
30 62
139+
27 64
140+
26 68
141+
25 71
142+
25 77
143+
25 81
144+
26 84
145+
28 86
146+
31 87
147+
33 88
148+
36 88
149+
39 86
150+
41 85
151+
43 83
152+
44 81
153+
45 76
154+
45 74
155+
45 71
156+
40 67
157+
37 65
158+
34 63
159+
33 61
160+
33 61
161+
32 60
162+
33 49
163+
37 45
164+
41 41
165+
45 39
166+
47 38
167+
51 37
168+
54 37
169+
58 38
170+
61 41
171+
63 44
172+
65 46
173+
66 49
174+
66 51
175+
67 55
176+
67 58
177+
67 60
178+
66 62
179+
64 65
180+
63 66
181+
61 67
182+
60 68
183+
58 68
184+
55 69
185+
54 69
186+
51 69
187+
48 69
188+
46 68
189+
45 66
190+
44 65
191+
44 63
192+
44 61
193+
44 59
194+
44 56
195+
44 55
196+
45 53
197+
47 52
198+
49 50
199+
50 48
200+
51 47
201+
52 46
202+
54 46
203+
55 45
204+
55 45
205+
56 44
206+
57 44
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/**
2+
* LoadFile 2
3+
*
4+
* Loads a data file about cars. Each element is separated with a tab.
5+
* Press a mouse button to advance to the next group of entries.
6+
* Translated to C++ Mode.
7+
*/
8+
9+
struct Record {
10+
std::string name;
11+
float mpg;
12+
int cylinders;
13+
float displacement;
14+
float horsepower;
15+
float weight;
16+
float acceleration;
17+
int year;
18+
float origin;
19+
20+
Record(std::vector<std::string>& pieces) {
21+
name = pieces[0];
22+
mpg = toFloat(pieces[1]);
23+
cylinders = toInt(pieces[2]);
24+
displacement = toFloat(pieces[3]);
25+
horsepower = toFloat(pieces[4]);
26+
weight = toFloat(pieces[5]);
27+
acceleration = toFloat(pieces[6]);
28+
year = toInt(pieces[7]);
29+
origin = toFloat(pieces[8]);
30+
}
31+
};
32+
33+
std::vector<Record> records;
34+
int num = 9;
35+
int startingEntry = 0;
36+
37+
void setup() {
38+
size(640, 360);
39+
fill(255);
40+
noLoop();
41+
textSize(20);
42+
43+
std::vector<std::string> lines = loadStrings("data/cars2.tsv");
44+
for (auto& line : lines) {
45+
std::vector<std::string> pieces = split(line, '\t');
46+
if ((int)pieces.size() == 9) {
47+
records.push_back(Record(pieces));
48+
}
49+
}
50+
}
51+
52+
void draw() {
53+
background(0);
54+
for (int i = 0; i < num; i++) {
55+
int thisEntry = startingEntry + i;
56+
if (thisEntry < (int)records.size()) {
57+
text(std::to_string(thisEntry) + " > " + records[thisEntry].name, 20, 20 + i * 20);
58+
}
59+
}
60+
}
61+
62+
void mousePressed() {
63+
startingEntry += num;
64+
if (startingEntry > (int)records.size()) {
65+
startingEntry = 0;
66+
}
67+
redraw();
68+
}

0 commit comments

Comments
 (0)