Processingをコマンドラインから引数つきで実行する方法
ProcessingでExportしてwindowsやmacでアプリケーションとして動かした際,
コマンドライン引数を付けたい場合があったときの対処方法.
もともとProcessingはJavaアプレットで動いてるので普通にmain関数になんか書けばおk
以下,ソース(test.pde)
import processing.serial.*; // 引数をsetupで引き継げるようにするための配列 static String[] newArgs; // デバッグモードか static int DEBUG = 0; /** * 初期処理 */ public static void main(String args[]) { newArgs = new String[args.length+2]; newArgs[0] = "--bgcolor=#FFFFFF"; newArgs[1] = "test"; for (int i=0;i<args.length;i++) { newArgs[i+2] = args[i]; String[] vals = args[i].split("="); if (vals[0].equals("debug")) { DEBUG = Integer.parseInt(vals[1]); } } PApplet.main(newArgs); } /** * セットアップ */ void setup() { size(320, 240); background(0); text("DEBUG: " + DEBUG, 15, 20, 70, 70); } /** * 描画 */ void draw() { }
Windows(XP)だと下記のような感じ
$ test.exe debug=1
Macだと下記のような感じ
open -a test.app --args debug=1