-
Notifications
You must be signed in to change notification settings - Fork 0
/
Metrophony.pde
170 lines (131 loc) · 4.58 KB
/
Metrophony.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
//Loading XML data from Chicago Public Transit API
// modeled after XMLYahooWeather Example
import oscP5.*; //used for comm with Max/Msp
import netP5.*; //used for retrieving data
OscP5 oscP5;
String[] trainLines = { //All the lines that are retrieved in this order
"Red", "Blue", "Brn", "G", "P", "Pink", "Y", "Org"
};
public boolean sendDataToMax = true;
public int maxTrains = 25; // the maximum amount of trains (size of array)
public TrainObj[][] myTrain = new TrainObj[trainLines.length][maxTrains]; // first dimension is each line, second dimension is a train
public float myLatReal = 41.881134025841824; // projectLatitude //monroe and dearborn //41.8723158; mydorn
public float myLonReal = -87.6301084757506; // projectLongitude //-87.6274733;
public float myAngleReal = 90.0; // direction in which project is facing
public float maxDistance = 6; // maximum relative distance for checking trains
int drawMode = 3; //processing visuals of trains, 0 = diagram, 1 = circular visualization
public boolean cartesian = false;
float drawWidth = 250; //250;
float drawHeight = drawWidth * 0.8;
float widthOffset = 100;
float heightOffset = 100;
public float mapLon1 = -87.674635;
public float mapLon2 = -87.611078;
public float mapLat1 = 41.896879;
public float mapLat2 = 41.867340;
//greetingManager
IntList trains1;
IntList trains2;
ArrayList <circleFade> circles;
PImage map;
//thread
TimerThread pollThread;
TimerThread greetingThread;
TimerThread triggerThread;
NetAddress myBroadcastLocation; // these are the api url details with the key at the end.
String urlBase = "http://lapi.transitchicago.com/api/1.0/ttpositions.aspx?key=0a18a0c2169b4fa4bc5e636ba5ee81f6&rt=";
void setup() {
size(1689,1042);
smooth(30);
frameRate(60);
map = loadImage("Img/chicagoMap2.png");
drawWidth = width;
drawHeight = height;//width*((mapLat1-mapLat2)/(mapLon2+mapLon1));
// for incoming messages
oscP5 = new OscP5(this, 12000);
// for sending messages
myBroadcastLocation = new NetAddress("127.0.0.1", 32000);
//initialize enough train objects
for (int i = 0; i < trainLines.length; i++) {
for (int j = 0; j < maxTrains; j++) {
myTrain[i][j] = new TrainObj();
}
}
// http://lapi.transitchicago.com/api/1.0/ttpositions.aspx?key=0a18a0c2169b4fa4bc5e636ba5ee81f6&rt=org
//greetingManager
trains1 = new IntList();
trains2 = new IntList();
circles = new ArrayList <circleFade>();
//initialize thread
int pollPerMinute = 30; //amount of checks per minute
pollThread = new TimerThread(pollPerMinute);
pollThread.running = true;
pollThread.task = 1;
pollThread.start(); //needs to be called
int checkPerMinute = 120;
greetingThread = new TimerThread(checkPerMinute);
greetingThread.running = true;
greetingThread.task = 2;
greetingThread.start();
int checkTriggerSpeed = 240;
triggerThread = new TimerThread(checkTriggerSpeed);
triggerThread.running = true;
triggerThread.task = 3;
triggerThread.start();
//ini path
}
void draw() {
background(0);
image(map,0,0);
print("newframe");
drawData(drawMode);
drawGreetingCircles();
stroke(0);
noFill();
strokeWeight(width/2);
//ellipse(width/2,height/2,height+width/2,1080+width/2);
}// end of draw
/* incoming osc message are forwarded to the oscEvent method. */
void oscEvent(OscMessage theOscMessage) {
/* get and print the address pattern and the typetag of the received OscMessage */
// println("### received an osc message with addrpattern "+theOscMessage.addrPattern()+" and typetag "+theOscMessage.typetag());
theOscMessage.print();
String addrPattern = theOscMessage.addrPattern();
println("new message " + random(100));
if (addrPattern.equals("trainTrigger")){
int lineNumber = 0;
for (int i = 0; i<trainLines.length;i++) {
String line = theOscMessage.get(0).stringValue();
if (line.equals(trainLines[i])){
lineNumber = i;
break;
}
}
int trainNumber = theOscMessage.get(1).intValue();
// if(theOscMessage.get(1).intValue() == 2){
myTrain[lineNumber][trainNumber].l = color(255,255,255);
// }
}
}
void keyReleased(){
if (key == 'q'){
drawMode += 1;
drawMode %= 4;
drawMode += 1;
fill(150);
rect(0,0,width,height);
}
}
void mouseReleased(){
// greetingManager();
circles.add(new circleFade(mouseX,mouseY, 250,500,500,125,0));
myTrain[1][0].trigger();
int[] meetDataInt = {};
float[] meetDataFloat={45,1.1};
String[] meetDataString={"blue","pink"};
sendExtra("Meet",meetDataInt,meetDataFloat,meetDataString);
}
void exit()
{
super.exit();
}