Alternate paradigm for progress bar?
in
Programming Questions
•
1 year ago
This is my first processing program. It is basic but functional. It pulls a number 0 < N < 100 from a data.txt file which is then displayed on the progress bar as a % completed. I am sure there are a zillion different ways to implement this - I would like to know how you would do it to give me some different ways to think about it. I basically just used the
reference page to find functions that seemed useful and then played with them until I could make it work.
First I went for a static program:
------------------------------
size(600,100);
String data[] = loadStrings("C:UEliDocuments750words_scraperdata.txt");
float data_num = float(data[0]);
fill(255);
rect(30,30,400,20);
fill(0);
rect(30,30,4*data_num,20);
text("I am "+data_num+"% of the way there!", 50,80);
-----------------------------------
Which worked fine enough, but I wanted to animate the progression of the inner rectangle, so after a false start or two I made it dynamic:
--------------------------------
String data[] = loadStrings("C:UEliDocuments750words_scraperdata.txt");
float data_num = float(data[0]);
float multiplier = 0;
void setup() {
size(600,100);
frameRate(70);
}
void draw(){
fill(255);
rect(30,30,400,20);
fill(0);
if (multiplier < 4){
multiplier+=.25;
}
rect(30,30,multiplier*data_num,20);
text("I am "+data_num+"% of the way there!", 50,80);
}
------------------------------------------
the frameRate and multiplier+= values were chosen just by playing with them until I found a speed that I liked. Because I have an absolute 400 px width for the progress bar, multiplier caps out at 4 for 100%. Ideally, I would like to be able to define a static animation time of something like a quarter or half a second and have the animation speed dynamically change to accommodate that, but I haven't figured that out yet. I'm also certain that I could have used the scale or shape functions, but I didn't bother with scale and I couldn't get the syntax down for createShape or PShape.
So. How would you do it?
1