We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hello, everyone! I am working on a school project, photoshop. When I use the blur effect it takes a very long time. So, I want to tell the user, how much progress has the algorithm made so far. I have a single function doing all the work. Inside that function is a for loop and the most work is done inside that for loop.
The only values it is showing me are 0% and 100%. I want to find a way to either draw the progress bar individually or redraw the whole screen inside that for loop.
Thx for help in advance.
Answers
best bet to rewrite the for loop so that it uses the fact that draw() in itself loops
so let's say now you have
for(int i..........
instead declare i before
setup()
and increase it at the end ofdraw()
use
i
in your function but without the for-loopwhen
i
has reached the maximum change thestate
and stop displaying the progress barThat's that I thought too. Rewriting the for loop and executing it one by one at runtime. However, my teacher wants a single function to do all the work. So, I can't use that, but thanks for your answer anyways.
I recently learned to use thread(). Any solutions for that?
I tried using a variable to indicate the progress and to draw the current progress and then running the blur function in a separate thread updating the variable. For some reason it didn't work...
That should work
Post your attempt
It didn't work. Then I tried to do the same, but with a text file instead. In both cases, when I inputed a dark purple image, the screen started flickering purple.
Just now, I might have come up with a solution. I have a question though. Does the thread loop or does it run the code once. And, if it loops, how do I stop it? I need the thread to run only once.
I'll post my attempt later. I dont have my laptop with me. :P
Maybe return in the function you called with thread()?
Is that, how you terminate a thread?
So, now my problem boils down to how do I change a variable from a thread. The thread grabs an image, processes it and returns it. The problem now is that I have a variable called
effectProgress
and it is used two times:In drawing function:
if(darkTheme){ stroke(#2F2F2F); strokeWeight(3); line(0, mainCluster.getValue("height") + 20, width, mainCluster.getValue("height") + 20); stroke(#FFFFFF); strokeWeight(3); line(0, mainCluster.getValue("height") + 20, width * progress, mainCluster.getValue("height") + 20); } else{ stroke(#9F9F9F); strokeWeight(3); line(0, mainCluster.getValue("height") + 20, width, mainCluster.getValue("height") + 20); stroke(#000000); strokeWeight(3); line(0, mainCluster.getValue("height") + 20, width * progress, mainCluster.getValue("height") + 20); }
In the function in the new thread:
returnImage.loadPixels(); for(int x = 0; x < returnImage.width; x ++){ for(int y = 0; y < returnImage.height; y ++){ returnImage.pixels[x + y * pic.width] = effectBlurGetPixel(x, y, pic, matrix, blurAmount); effectProgress = (x + y * pic.width) / pic.pixels.length; } }
the new thread doesn't seem to influence the new animation thread.
I don't know, how I did it, but it is working. I need help with screen flickering. It is like while the function is running, when the new thread edits a pixel in the image, the animation thread takes the color as input in fill() or stroke(). I'll record it and send you a link.