Hello,
I am new to Processing (and I learned Java almost 3 years ago so I’m a little rusty). I am trying to make an animation of several bike-riding trips over a 24-hour period. The time lapses at a good speed while there is a trip to plot (about 1 hour every second), but I was wondering if I can “fast-forward” when there’s no data to plot, and then go slower when there is a trip.
If this is possible, would I have to hard-code a time period(s) to fast forward through, or could I have the time periods determined from the data table?
My code snippets are below. I’m not particularly interested in altering the point-plotting speed, but would like it to go faster when it has no points to plot.
Here is my setup():
void setup() {
img = loadImage("map.png"); // load the map
surface.setSize(img.width, img.height); // set window size using the map picture size
frameRate(1000); // note the frame rate is restricted to the hardware
locationTable = loadTable("data.csv"); // load the GPS data
// The row count will be used a lot, so store it globally.
rowCount = locationTable.getRowCount( );
println(rowCount);
// set the initial time
time = locationTable.getInt(0, 0);
initialHr = locationTable.getInt(0, hourCol);
initialMin = locationTable.getInt(0, minCol);
initialSec = locationTable.getInt(0, secCol);
currentHr = initialHr;
currentMin = initialMin;
currentSec = initialSec;
} //setup()
And here is part of draw(), where I update the time:
//update current time
if (currentSec < 45){
currentSec+= 15;
}else if (currentSec >=45 && currentMin < 59){
currentSec = 0;
currentMin++;
}else if (currentSec >= 45 && currentMin == 59 && currentHr < 23){
currentSec = 0;
currentMin = 0;
currentHr++;
}else if (currentSec >= 45 && currentMin == 59 && currentHr == 23){
currentSec = 0;
currentMin = 0;
currentHr = 0;
}
// display the time of day info on the image
textAlign(RIGHT, CENTER);
fill(100, 100, 100); // RGB color of the text
textSize(28);
if (time < 86400) {
if (currentHr < 12) {
text(nf(currentHr, 2, 0) + ":" + nf(currentMin, 2, 0) + " AM", 150, 40);
}else if (currentHr == 12) {
text(12 + ":" + nf(currentMin, 2, 0) + " PM", 150, 40);
}else if (currentHr < 24) { //hours > 12
text(nf(currentHr - 12, 2, 0) + ":" + nf(currentMin, 2, 0) + " PM", 150, 40);
}else {
text(nf(currentHr - 24, 2, 0) + ":" + nf(currentMin, 2, 0) + " AM", 150, 40);
}
}else { // after 24 hours of data
text(nf(initialTimeOfDay, 2, 0) + ":00 AM", 150, 40);
}
Thank you!