We are about to switch to a new forum software. Until then we have removed the registration on this forum.
Hi,
I recently taught a course on Computational Graphic Design, and the students have all handed in their assignments. This leaves me with a folder and several subfolders packed with Processing sketches. To get a visual overview of their assignments, I would like to automate the process of 1) traversing the folder structure, 2) opening all encountered ".pde" files one at a time, 3) run the open sketch, and 4) save the canvas - either directly from within Processing or via any third party software. Being able to do so will save me a lot of time, but I haven't got the slightest clue about how to make this happen. Any input will be highly appreciated. Thanks!
Answers
@Stixan -- Interesting teaching question.
One approach is to discover sketches with a shell script, run each sketch from the command line, however run a modified version that injects a call to
saveFrame().
Traversing the directories
note that, like Java classes, the only pde files you need to check for are ones with match their folder name exactly -- e.g. for these pdes:
You should only run:
This is not a valid sketch:
Running from the command line
Once you have your sketch list and are looping through running them, use the command line interface:
Like this:
Adding saveFrame
Assuming you don't have any sketches with animation, you want to add a call to
saveFrame()
after the first full draw loop (unless the sketch is written in immediate mode). Here are two ways of doing thatdraw()
whenframeCount==2
void post(){}
For the draw() approach, assuming that each sketch has this line:
...then you could replace it (in a copy, or dynamically at run time) with this:
...however note that this assumes
noLoop()
is not set andexit()
is not manually called after the first frame.Alternately you instead add
saveFrame()
to the end of the draw loop -- but this can't be done reliably with search and replace, you need to either do it manually or parse the code.For the library approach, create a simple library which defines a
post()
method to run immediately after draw. Register the method:...then prepend any sketch you run with a line importing your library:
Adding saveFrame to Immediate mode
I'm not actually sure if a library with
post()
works for sketches written in immediately mode (i.e. sketches with nodraw()
orsetup()
) -- I think it does. However, if the sketch does not contain "void draw" then it is written in immediate mode, and you can simply appendsaveFrame();
as the last line (...assuming it doesn't call exit() -- if it does, you need to prepend it above the exit line).Related past discussions:
P.S. Another approach in the future is to require that students end all their static sketches with a call to
saveFrame()
.Wow, thanks @jeremydouglass! Pretty detailed plan of how to attack this problem. I'll look into it, but I have a sneaking suspicion that I might be coming back to kindly ask that you elaborate on a number of the steps.
I gave it a shot but didn't manage to get it working. Accepting @jeremydouglass answer though, as I think it is the right way to solve what I initially asked to do. Personally I'm simply lacking the skills required to get it to work.
I am not sure if this could help as you need to provide the .java files directly into this sketch as suggested in this post: http://forum.happycoding.io/t/how-to-make-a-processing-showcase/83/2
@jeremydouglass Is it possible to generate the java file and place it in a gfolder inside the sketch folder? I think it is worth it to implement a demo to do this. However, there are some restrictions to consider when doing something like this.... for example, a sketch calling exit or having calls to noLoop()....
Kf
An answer to my question in the next post thxs to @lesmana: https://forum.processing.org/two/discussion/23400/how-to-get-the-generated-java-code#latest
Kf