forked from blprnt/dataart_old
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdanigrant-assignment1
More file actions
229 lines (207 loc) · 6.01 KB
/
danigrant-assignment1
File metadata and controls
229 lines (207 loc) · 6.01 KB
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
import processing.opengl.*;
import java.util.*;
import twitter4j.conf.*;
import twitter4j.internal.async.*;
import twitter4j.internal.org.json.*;
import twitter4j.internal.logging.*;
import twitter4j.json.*;
import twitter4j.internal.util.*;
import twitter4j.management.*;
import twitter4j.auth.*;
import twitter4j.api.*;
import twitter4j.util.*;
import twitter4j.internal.http.*;
import twitter4j.*;
import twitter4j.internal.json.*;
import processing.opengl.*;
import java.util.*;
//visual things
Sphere mySphere;
float opacity;
String[] colorList = {
"ff8c510a",
"ffbf812d",
"ffdfc27d",
"fff6e8c3",
"fff5f5f5",
"ffc7eae5",
"ff80cdc1",
"ff35978f",
"ff01665e"
};
//twitter things
StatusListener listener;
boolean tweeted = false;
PFont font;
void setup() {
size(500, 500, OPENGL);
mySphere = new Sphere(250.0, 250.0, 250.0, 50.0);
mySphere.init();
background(255);
opacity = 5; //opacity and color show recency b/c it's real time
mySphere.addSphereItem();
smooth();
/*//font
font = createFont("Helvetica Neue", 20, true);
textFont(font);
textMode(CENTER);
textAlign(CENTER);*/
//config Twitter
//Configurations
ConfigurationBuilder cb = new ConfigurationBuilder();
cb.setOAuthConsumerKey("R9xCaEX4NqxibhYyzgGg");
cb.setOAuthConsumerSecret("Y6lQAZqlM3LznJLzEXi67Rfjhs8DnSwaTDEMcs71VI");
cb.setOAuthAccessToken("480959060-XbLrc0qS0WuT2Q8pFSXpJTVsdRZIxn0rP7cx2YYQ");
cb.setOAuthAccessTokenSecret("hkHarLtZm16QUUnlD32HD5LivTYk4RR935Y2zkulqUo");
//init twitter
TwitterStream twitterStream = new TwitterStreamFactory(cb.build()).getInstance();
try {
listener = new StatusListener() {
public void onStatus(Status status) {
println("status");
tweeted = true;
}
public void onDeletionNotice(StatusDeletionNotice statusDeletionNotice) {
}
public void onTrackLimitationNotice(int numberOfLimitedStatuses) {
}
public void onStallWarning(StallWarning warning) {
}
public void onScrubGeo(long x, long y) {
}
public void onException(Exception ex) {
ex.printStackTrace();
}
};
}
catch (Exception ex) {
println("Couldn't connect.");
}
//add listener to the stream
twitterStream.addListener(listener);
//init filtering
FilterQuery filter = new FilterQuery();
String[] keywordsArray = {
"food", "hungry", "meal", "yum", "eat", "nom", "dinner", "tasty", "delicious", "halal", "restaurant", "food truck", "want food"
};
filter.track(keywordsArray);
twitterStream.filter(filter);
}
void draw() {
fill(#d1e5f0);
//text("twitter is hungry", width/2, height/7, 20);
if (tweeted) {
yes();
tweeted = false;
}
}
void yes() {
println("yes called");
//white overlay for fade effect
fill(255, opacity);
rect(0, 0, width, height);
//parameters change the drawing
float size = 1.9;
color c = getColor(.3); //chosen based on taste when the program runs but can be any num b/ween 0 and 1
float tS = 2; //chosen by taste but can be any float pos or neg
float pS = -1.001; //chosen by taste
mySphere.update(size, c, tS, pS); //size mapped from 1.6 to 2.6, getColor(map(f, 0, 100, 0, 1)), theta, phi
mySphere.render();
};
color getColor(float f) {
//f is a number between 0 and 1
//convert it to an int to pick from the array
int i = floor(f * (colorList.length - 1));
color col = unhex(colorList[i]);
return(col);
}
class Sphere {
float xPos; //X Position of the Sphere
float yPos; //Y Position of the Sphere
float zPos; //Z Position of the Sphere
float radius; //Radius of the Sphere
ArrayList items = new ArrayList(); //List of all of the items contained in the Sphere
public Sphere(float x, float y, float z, float r) {
xPos = x;
yPos = y;
zPos = z;
radius = r;
};
public void init() {
};
public void update(float size, color c, float tS, float pS) {
for (int i = 0; i < items.size(); i ++) {
SphereItem si = (SphereItem) items.get(i); // Cast the returned object to the SphereItem Class
si.update(size, c, tS, pS);
};
};
public void render() {
//Move to the center point of the sphere
translate(xPos, yPos, zPos);
//Mark position in 3d space
pushMatrix();
//Render each SphereItem
for (int i = 0; i < items.size(); i ++) {
SphereItem si = (SphereItem) items.get(i);
si.render();
};
//Go back to original position in 3d space
popMatrix();
};
public void addSphereItem() {
//Make a new SphereItem
SphereItem si = new SphereItem();
//Set the parent sphere
si.parentSphere = this;
//Set random values for the spherical coordinates
si.theta = PI;
si.phi = 2 * PI;
//Add the new sphere item to the end of ArrayList
items.add(items.size(), si);
si.init();
};
};
class SphereItem {
Sphere parentSphere;
//Spherical coordinates
float radius;
float theta; //latitude
float phi; //longitude
//Speed properties
float thetaSpeed = 0;
float phiSpeed = 0;
//Size
float itemSize = 5;
public void SphereItem() {
};
public void init() { //thetaspeed of 2 and phi speed of -1.001 is awesome
itemSize = random(1.7, 2.5);
thetaSpeed = 2;
phiSpeed = -1.001; //bigger is more loops
};
public void update(float size, color c, float tS, float pS) {
itemSize = size; //random(1.7, 2.5);
fill(c); //probably be a mapping with the rate of usage of something. red and blue like a heat map for instance
theta += thetaSpeed;
phi += phiSpeed;
};
public void render() {
//Get the radius from the parent Sphere
float r = parentSphere.radius;
//Convert spherical coordinates into Cartesian coordinates
float x = cos(theta) * sin(phi) * r;
float y = sin(theta) * sin(phi) * r;
float z = cos(phi) * r;
//Mark our 3d space
pushMatrix();
//Move to the position of this item
translate(x, y, z);
//Set the fill colour
//fill(#ff6600, 50);
noStroke();
//Draw a circle
ellipse(0, 0, itemSize, itemSize);
//Go back to position in 3d space
popMatrix();
};
};