|
Author |
Topic: key/value pairing ala dictionary in proce55ing? (Read 593 times) |
|
waxpraxis
|
key/value pairing ala dictionary in proce55ing?
« on: Jul 18th, 2003, 6:13pm » |
|
I've only been playing with proce55ing for a few days and I've hit a big of snag that's preventing me from porting some of my ActionScript work over... I can't seem to find a way to do key/value pairing! In particular, I'm working on some L-Systems stuff, and want to associate a certain character with an array of characters (the rules and their symbol). In AS it would be as simple as this: foo = new Object(); foo['f'] = ['+','f','-']; I can't seem to find any equivilent in proce55ing, and all of my attempts at rolling my own class for handling this have been twarted by the fact that the last time I did so it was in C++ and so all of the solutions I know of use pointers! Thanks in advance for any and all suggestions.
|
|
|
|
fry
|
Re: key/value pairing ala dictionary in proce55ing
« Reply #2 on: Jul 21st, 2003, 5:00pm » |
|
yep, the equiv. for p5 (actually, it's just java) is: Code:Hashtable table = new Hashtable(); char list[] = { '+', 'f', '-' }; void setup() { // stuff it in table.put(new Character('f'), list); // to get it back char thegoods[] = (char[]) table.get(new Character('f')); } |
| it's a little awkward.. hash tables are for objects, which means you have to wrap your chars up in a character object.. not quite optimal. hmmm... seems like some easy to use lookup table / associative array setup would help a bit...
|
|
|
|
waxpraxis
|
Re: key/value pairing ala dictionary in proce55ing
« Reply #3 on: Jul 21st, 2003, 5:39pm » |
|
Thanks for all of the info - and yes, please, any kind of p5 wrapper for hashtables would be a wonderful thing! It's really quite nice in ActionScript, being able to just use key/value pairs and not have to think too much about syntax. Similarly, it would be great if p5 arrays could fully act like AS arrays - with push, pop, etc. Also, since I did just step into p5 a week or so ago, I wasn't aware that you had access back down to Java classes automatically... I was trying to find some sort of include directive in p5 to load up the classes! Which packages are loaded in to p5 by default? All of java.util and what else?
|
|
|
|
fry
|
Re: key/value pairing ala dictionary in proce55ing
« Reply #4 on: Jul 22nd, 2003, 10:49pm » |
|
all the java.* from 1.1 is included for exported applets. let's see here: the applet imports from below are what's available during export. the application exports are those available when running inside the environment. and the ones around #ifdef 1.3 are on platforms using at least java 1.3, same for the #ifdef 1.4 stuff. Code: static final String applet_imports[] = { "java.applet", "java.awt", "java.awt.image", "java.awt.event", "java.io", "java.net", "java.text", "java.util", "java.util.zip" }; static final String application_imports[] = { "java.applet", "java.awt", "java.awt.image", "java.awt.event", "java.io", "java.net", "java.text", "java.util", "java.util.zip", "javax.comm", // if jdk14 defined, jdk13 will be as well #ifdef JDK13 "javax.sound.midi", "javax.sound.midi.spi", "javax.sound.sampled", "javax.sound.sampled.spi", #endif #ifdef JDK14 "javax.xml.parsers", "javax.xml.transform", "javax.xml.transform.dom", "javax.xml.transform.sax", "javax.xml.transform.stream", "org.xml.sax", "org.xml.sax.ext", "org.xml.sax.helpers" #endif }; |
| hope this is enough explanation.. writing reply very hastily..
|
|
|
|
|