I am trying to get some parameters into a compiled sketch by running the sketch from the command line and specifying the parameters after the compiled sketch filename. As a start, I used the example from at
http://wiki.processing.org/w/Setting_width/height_dynamically, but I can't seem to make it work.
Here's the sketch (based on above link and a few lines of the setup code that I put):
- /**
- dynamicsize taken from http://www.processinghacks.com/hacks/dynamicsize
- @author toxi (http://www.processinghacks.com/user/toxi)
- */
- // this table is used to store all command line parameters
- // in the form: name=value
- static Hashtable params=new Hashtable();
- // here we overwrite PApplet's main entry point (for application mode)
- // we're parsing all commandline arguments and copy only the relevant ones
- static public void main(String args[]) {
- String[] newArgs=new String[args.length+1];
- /*********************************************************
- /* IMPORTANT: replace this with the name of your sketch *
- /*********************************************************/
- newArgs[0]="DynamicSizeDemo";
- for(int i=0; i<args.length; i++) {
- newArgs[i+1]=args[i];
- if (args[i].indexOf("=")!=-1) {
- String[] pair=split(args[i], '=');
- params.put(pair[0],pair[1]);
- }
- }
- // pass on to PApplet entry point
- PApplet.main(newArgs);
- }
- // now we also overwrite the default param() function
- // if we're not online (i.e. running as application), the new function
- // will use the Hashtable to find the param
- String param(String id) {
- if (online) return super.param(id);
- else return (String)params.get(id);
- }
- void setup(){
- size(param(0), param(1);
- }
- void loop(){
- background(0);
- }
What I am trying to get the parameters from the command line dynamically, like following, let's say my app is program.exe:
- program.exe width=800 height=600
What am I doing it wrong with the above sketch?
1