-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfacebook_visu.pde
executable file
·272 lines (175 loc) · 6.01 KB
/
facebook_visu.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
// networking stuffs
import oscP5.*;
import netP5.*;
OscP5 oscP5;
NetAddress myRemoteLocation;
String oscIP = "127.0.0.1";
int oscPort = 10000;
import controlP5.*;
Graph graph; //this object groups the graph diagram
Controlbutton controlbutton; //and this one the button interface above
G_table tG; //this is the group of tables we are going to use
color [] colores = {#5E72AA,#5A8DCE};
color
BACKGROUND_COLOR = #ffffff,
TEXT_COLOR = color(255);
int n = 6; //number of tables
int number_of_posts = 10;
ControlP5 cp5;
// define the chart
Chart Posts;
String post_msg = "What was in his Mind ?";
color post_color = color (0, 102, 153, 100);
// Photo Array
ArrayList <PImage> photo_list;
PImage Users_photo_Fram;
ArrayList <String> users_name;
// update loading gif
PImage[] animation;
boolean updating = false;
String imagePrefix = "./updating/tmp-";
int image_count = 8;
int frame;
void setup(){
size(displayWidth,displayHeight);
background(BACKGROUND_COLOR);
noStroke();
smooth();
cursor(CROSS);
ellipseMode(RADIUS);
colorMode(HSB);
animation = new PImage[image_count];
// updating animation array
for (int i = 0; i < image_count; i++) {
// Use nf() to number format 'i' into four digits
String filename = imagePrefix+i+".gif";
animation[i] = loadImage(filename);
}
// OSC input port
oscP5 = new OscP5(this, 10001);
// OSC output port
myRemoteLocation = new NetAddress(oscIP, oscPort);
// controlp5 instances
cp5 = new ControlP5(this);
// create PIE chart for Post Types
Posts = cp5.addChart("Posts")
.setPosition(250, 100)
.setSize(500, 500)
.setRange(0, 10)
.setView(Chart.PIE)
;
Posts.getColor().setBackground(color(255, 100));
Posts.addDataSet("Post_Types");
Posts.setColors("Post_Types", color(0,0,255) , color(0,255,0) );
// make update button
cp5.addButton("UpdateFacebook")
.setPosition(displayWidth/2.5,displayHeight/1.63)
.setSize(200,19);
cp5.addSlider("Number_Of_Posts")
.setPosition(displayWidth/4.5,displayHeight/1.75)
.setWidth(600)
.setHeight(20)
.setRange(10,500) // values can range from big to small as well
.setValue(20)
.setNumberOfTickMarks(50)
.setSliderMode(Slider.FLEXIBLE)
;
//constructing objects
tG = new G_table(n);
graph = new Graph(tG,width/2.0,height/3,250,18,50000);
controlbutton = new Controlbutton(n,displayWidth/8,displayHeight/8,30,tG.getMaxSum(),tG.getSums(),tG.getTitles());
}
void draw(){
fill(0,50);
rect(0, 0, width, height);
setCursor(); //set the cursor
if (graph.isShifting()) { //if we are shifting data shift the radiuses of the current element
graph.getCurrentElement().shiftTo(graph.getCurrentIndex());
}
graph.displayTodo(); //display the element
controlbutton.display(); //display the buttons above
if (updating !=true){
show_my_profile();
show_photo();
}
else {
// show updating icon
play_updating_visualization();
}
}
void play_updating_visualization(){
frame = (frame+1) % image_count;
image(animation[frame],displayWidth/2.25,displayHeight/1.5,100,100);
}
void show_my_profile(){
// show post box
fill(255);
rect(displayWidth/4.5,displayHeight/1.55,700,80, 9);
fill(post_color);
text(post_msg,displayWidth/3.55,displayHeight/1.52,400,60);
// data column
String data[][];
data = new String[1][2];
// open the file
String[] post_file = loadStrings("./data/profile.tsv");
int file_lenght = post_file.length;
data[0] = split(post_file[1],"\t");
// show profile picture
String photo_path = "./data/user_photos/" + data[0][1]+".jpg" ;
image(loadImage(photo_path),displayWidth/4.25,displayHeight/1.52);
}
void show_photo(){
if (graph.photo_list_filled == true){
float x_dir=10,y_dir=height/1.32;
if(photo_list.size() !=0){
fill(255);
textSize(8);
for (int i=0;i<photo_list.size();i++){
Users_photo_Fram = photo_list.get(i);
// show image
image(Users_photo_Fram,x_dir,y_dir);
text(users_name.get(i),x_dir,y_dir+60);
if (x_dir < width -100){
x_dir +=80;
}
else {
x_dir = 10;
y_dir +=80;
}
}
}
textSize(12);
graph.photo_list_filled = false;
}
}
public void controlEvent(ControlEvent theEvent) {
println(theEvent.getController().getName());
}
public void UpdateFacebook(int theValue) {
// send request for new data to other processing app
OscMessage update = new OscMessage("/update_facebook");
update.add(number_of_posts);
oscP5.send(update, myRemoteLocation);
updating = true;
}
void Number_Of_Posts(int Number_Of_Post) {
number_of_posts = Number_Of_Post;
}
void oscEvent(OscMessage theMessage) {
// check if the address is correct
if (theMessage.checkAddrPattern("/completed")==true) {
// check the type tag to be correct
if(theMessage.checkTypetag("i")) {
int message_val = theMessage.get(0).intValue();
if (message_val == 1){
updating = true;
print("making the tables ...");
// make the tables
tG=new G_table(n);
graph = new Graph(tG,width/2.0,height/3,250,18,50000);
controlbutton = new Controlbutton(n,displayWidth/8,displayHeight/8,30,tG.getMaxSum(),tG.getSums(),tG.getTitles());
updating = false;
}
}
}
}