You can create a simple progress bar in Processing using the rect() function to draw a rectangle that represents the progress. Here’s an example of how to create a basic horizontal progress bar:…
…
In this example, we start with a progress bar of width zero and gradually increase its width in the draw() function. You can adjust the progressBarWidth increment and the frameRate to control the speed of progress.
To use this code, copy it into a Processing sketch, and then run the sketch. You should see a basic horizontal progress bar that fills from left to right. You can customize the appearance and behavior of the progress bar to fit your specific needs.
//
int progressBarWidth = 0; // Initial progress bar width
int maxProgressBarWidth = 400; // Maximum width of the progress bar
void setup() {
size(700, 100);
frameRate(30); // Adjust the frame rate as needed
}
void draw() {
background(220); // Set the background color
// Update the progress bar width
progressBarWidth += 2; // You can change this value to control the progress
// Ensure the progress bar doesn't exceed its maximum width
if (progressBarWidth > maxProgressBarWidth) {
progressBarWidth = maxProgressBarWidth;
}
// Draw the progress bar outline
stroke(0);
noFill();
rect(50, 40, maxProgressBarWidth, 20);
// Draw the filled part of the progress bar
fill(0, 128, 0); // Green color for the progress
noStroke();
rect(50, 40, progressBarWidth, 20);
}