I'd like to save user preferences from a sketch running either on a PC or an Android phone, using the same code in as standard "Java-way" as possible.
Ideal candidate for my purposes seems to be the java.util.prefs.Preferences class. So, I wrote a little test script to see if it's working in processing:
This program outputs an increasing number each time it is executed - on a PC. On Android, the default value (0) is always shown.
Are there any additional steps required to get this working on Android? Permissions to be requested?
Are there any alternatives for saving name - value pairs on both platforms?
For printing purposes, I needed to re-render one of my sketches in high-resolution. I've searched for ways to do this, but the only one I found was overly complicated and required me to re-write my whole script (for the purposes of tile-by-tile rendering).
That was not what I wanted - I wanted a simple way to switch between high-res and normal rendering, without a need to rewrite anything in the actual code.
After bit more research I come with a hack. It allows me, by appending it's code at the beginning of any script (which produces its result dynamically depending on width/height properties), to render the result in any resolution*.
* - Up to the java memory limit. Last time I checked, it was about 1.2 GB, even when machine I'm using has much more than that.
I have used this only twice, so I'm not aware about any other limitations, or side effects of this technique.
Finally, example script:
int sx = 5000; int sy = 5000;
/* THE HACK */ g = createGraphics(sx,sy,JAVA2D); this.height = sy; this.width = sx; g.beginDraw(); /* THE HACK end */
/* Example sketch start */ color c1 = #AFA786; color c2 = #000000;
for (int y=0; y<=height; y++) { stroke(lerpColor(c1,c2,float(y)/height)); line(0,y,width,y); }
stroke(#FFFFFF); fill(#BBBBBB); ellipse(width/2, height/2, width/2, height/2); line(0, 0, width, height); /* Example sketch end */
g.endDraw(); /* THE HACK tail */
save("result.png");
This script renders 5000x5000 pixels image (partially visible on the screen) and saves it into the file, while using example sketch with basic, regular, unmodified syntax.
My questions are:
- Is there a non-hackish, 'proper' yet still simple way to do this?
- Are there any obvious disadvantages to this solution?