gpt4 book ai didi

processing - 循环播放 PDE 文件?

转载 作者:行者123 更新时间:2023-12-05 01:36:35 24 4
gpt4 key购买 nike

我对 Processing 还是比较陌生。我们正在考虑在一个小型展览中循环展示我们的处理工作。有没有办法循环播放多个 PDE?我知道我可以导出为帧,然后将它们组合成更长的可循环播放的 Quicktime 文件,但我想知道是否有任何方法可以播放和循环播放文件本身?

此外,对于交互式 PDE,呈现它们的最佳方式是什么?我们正在考虑让几台计算机在 Processing 中运行 PDE,但让一个文件运行 20 分钟然后打开另一个文件 20 分钟会更好。

提前致谢!

最佳答案

您应该能够将使用 processing-java command line executable 的 shell/批处理脚本放在一起.

您应该能够通过工具 > 安装“processing-java”

进行设置

Install processing-java menu item

如果您不习惯 bash/批处理脚本,您甚至可以编写一个启动 Processing sketches 的 Processing sketch

whoa!

这是一个非常粗略的使用 selectFolder() 的例子和 exec() :

final int SKETCH_RUN_TIME = 10000;//10 seconds for each sketch, feel free to change
ArrayList<File> sketches = new ArrayList<File>();

int sketchIndex = 0;

void setup(){
selectFolder("Select a folder containing Processing sketches:", "folderSelected");
}

void draw(){

}
void nextSketch(){
//run sketch
String sketchPath = sketches.get(sketchIndex).getAbsolutePath();
println("launching",sketchPath);
Process sketch = exec("/usr/local/bin/processing-java",
"--sketch="+sketchPath,
"--present");
//increment sketch index for next time around (checking the index is still valid, otherwise go back to 0)
sketchIndex++;
if(sketchIndex >= sketches.size()){
sketchIndex = 0;
}
//delay is deprecated so you shouldn't use this a lot, but as a proof concept this will do
delay(SKETCH_RUN_TIME);
nextSketch();
}

void folderSelected(File selection) {
if (selection == null) {
println("No folder ? Ok, maybe another time. Bye! :)");
exit();
} else {
File[] files = selection.listFiles();
//filter just Processing sketches
for(int i = 0; i < files.length; i++){
if(files[i].isDirectory()){
String folderName = files[i].getName();
File[] sketchFiles = files[i].listFiles();
boolean isValidSketch = false;
//search for a .pde file with the same folder name to check if it's a valid sketch
for(File f : sketchFiles){
if(f.getName().equals(folderName+".pde")){
isValidSketch = true;
break;
}
}
if(isValidSketch) {
sketches.add(files[i]);
}else{
System.out.println(files[i]+" is not a valid Processing sketch");
}
}
}
println("sketches found:",sketches);
nextSketch();
}
}

代码已注释,希望它易于阅读和遵循。系统将提示您选择包含要运行的草图的文件夹。

注意 1: 我在我的机器上使用了 processing-java 路径 (/usr/local/bin/processing-java ).如果您使用的是 Windows,这可能会有所不同,您需要更改它。

注意 2: processing-java 命令启动另一个 Process这使得在运行下一个草图之前关闭上一个草图变得很棘手。作为解决方法,您可以调用 exit()在您需要的时间之后在每个草图上。

注意3:代码不会递归遍历包含草图的选定文件夹,因此只会执行第一层草图,更深层次的内容应忽略。

关于processing - 循环播放 PDE 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42680407/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com