Can you manipulate frameRate/Speed of draw()?

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() {
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

// 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!

1 Like

Try modulo! Something like:
if (framecount % 30)) == 0 {
do something
}

Thanks for the reply. I’m not sure how using modulo with frameCount would help me here. I update the clock every 15 seconds and while updating every 30 seconds would be faster (am I understanding the point of your if-statement correctly?), I am not trying to increase the overall speed, or even speed it up at regular intervals.
The clock keeps going at the same rate whether or not there’s a point to show on the map. I want the clock to speed up when there are no datapoints in my table corresponding to the clock’s current time, and slow down when there are datapoints.
For example, if there’s no trips between 2AM and 5AM and then a trip from 5AM to 5:30AM, I want the clock to elapse faster from 2am to 5am, and then slow down from 5am to 5:30am.

I figured it out!
So when I plot the points, I loop through the table to find all points with a timestamp equal to the current timestamp, and an if-statement that plots the point if its timestamp==current time. I added a boolean value that is true if the if-statement is run (if a point is plotted) and false otherwise. I then change

``````if (currentSec < 45){
currentSec+= 15;
}else if (currentSec >=45 && currentMin < 59){
currentSec = 0;
currentMin++;
}else if (currentSec >= 45 && currentMin == 59 && currentHr < 23){
......
``````

to increment currentSec differently based on the boolean value:

``````if (plotted == true){
if (currentSec < 59){
currentSec+= 1;
}else if (currentSec >=59 && currentMin < 59){
......//other conditions
}else if (plotted == false){
if (currentSec < 30){
currentSec+= 30;
}else if (currentSec >=30 && currentMin < 59){
``````
2 Likes