A Blog Exploring Digital Art

Recently I've been looking at Povray, pyprocessing, and cfdg (version 3.0) as tools for creating digital images. I have branched two separate blogs where I mainly explore ruby/rp5. and processing.py

Monday, 18 May 2015

New JOGL P2D looks good on linux

Change back to jogl in latest processing seems good (P2D looks much better than JAVA2D with this sketch) note size has moved to settings() and sketchRenderer(), sketchHeight() and sketchWidth() are gone running in netbeans.
  1 import processing.core.*;
  2 import processing.video.*;
  4 public class AsciiVideo extends PApplet {
  6     /**
  7      * ASCII Video by Ben Fry.
  8      *
  9      *
 10      * Text characters have been used to represent images since the earliest
 11      * computers. This sketch is a simple homage that re-interprets live video
 12      * as ASCII text. See the keyPressed function for more options, like
 13      * changing the font size.
 14      */
 15     Capture video;
 16     boolean cheatScreen;
 18 // All ASCII characters, sorted according to their visual density
 19     String letterOrder
 20             = " .`-_':,;^=+/\"|)\\<>)iv%xclrs{*}I?!][1taeo7zjLu"
 21             + "nT#JCwfy325Fp6mqSghVd4EgXPGZbYkOA&8U$@KHDBWNMR0Q";
 22     char[] letters;
 24     float[] bright;
 25     char[] chars;
 27     PFont font;
 28     float fontSize = 1.5f;
 30     @Override
 31     public void setup() {
 33   // This the default video input, see the GettingStartedCapture 
 34         // example if it creates an error
 35         video = new Capture(this, 160, 120);
 37         // Start capturing the images from the camera
 38         video.start();
 40         int count = video.width * video.height;
 41         //println(count);
 43         font = loadFont("UniversLTStd-Light-48.vlw");
 45   // for the 256 levels of brightness, distribute the letters across
 46         // the an array of 256 elements to use for the lookup
 47         letters = new char[256];
 48         for (int i = 0; i < 256; i++) {
 49             int index = PApplet.parseInt(map(i, 0, 256, 0, letterOrder.length()));
 50             letters[i] = letterOrder.charAt(index);
 51         }
 53         // current characters for each position in the video
 54         chars = new char[count];
 56         // current brightness for each point
 57         bright = new float[count];
 58         for (int i = 0; i < count; i++) {
 59             // set each brightness at the midpoint to start
 60             bright[i] = 128;
 61         }
 62     }
 64     public void captureEvent(Capture c) {
 65         c.read();
 66     }
 68     @Override
 69     public void draw() {
 70         background(0);
 72         pushMatrix();
 74         float hgap = width / PApplet.parseFloat(video.width);
 75         float vgap = height / PApplet.parseFloat(video.height);
 77         scale(max(hgap, vgap) * fontSize);
 78         textFont(font, fontSize);
 80         int index = 0;
 81         video.loadPixels();
 82         for (int y = 1; y < video.height; y++) {
 84             // Move down for next line
 85             translate(0, 1.0f / fontSize);
 87             pushMatrix();
 88             for (int x = 0; x < video.width; x++) {
 89                 int pixelColor = video.pixels[index];
 90                 // Faster method of calculating r, g, b than red(), green(), blue() 
 91                 int r = (pixelColor >> 16) & 0xff;
 92                 int gr = (pixelColor >> 8) & 0xff;
 93                 int b = pixelColor & 0xff;
 95       // Another option would be to properly calculate brightness as luminance:
 96                 // luminance = 0.3*red + 0.59*green + 0.11*blue
 97                 // Or you could instead red + green + blue, and make the the values[] array
 98                 // 256*3 elements long instead of just 256.
 99                 int pixelBright = max(r, gr, b);
101                 // The 0.1 value is used to damp the changes so that letters flicker less
102                 float diff = pixelBright - bright[index];
103                 bright[index] += diff * 0.1f;
105                 fill(pixelColor);
106                 int num = PApplet.parseInt(bright[index]);
107                 text(letters[num], 0, 0);
109                 // Move to the next pixel
110                 index++;
112                 // Move over for next character
113                 translate(1.0f / fontSize, 0);
114             }
115             popMatrix();
116         }
117         popMatrix();
119         if (cheatScreen) {
120     image(video, 0, height - video.height);
121             // set() is faster than image() when drawing untransformed images
122            // set(0, height - video.height, video);
123         }
124     }
126     /**
127      * Handle key presses: 'c' toggles the cheat screen that shows the original
128      * image in the corner 'g' grabs an image and saves the frame to a tiff
129      * image 'f' and 'F' increase and decrease the font size
130      */
131     @Override
132     public void keyPressed() {
133         switch (key) {
134             case 'g':
135                 saveFrame();
136                 break;
137             case 'c':
138                 cheatScreen = !cheatScreen;
139                 break;
140             case 'f':
141                 fontSize *= 1.1f;
142                 break;
143             case 'F':
144                 fontSize *= 0.9f;
145                 break;
146         }
147     }
149     @Override
150     public void settings() {
151         size(640, 480, P2D);
152     }
154     static public void main(String[] passedArgs) {
155         String[] appletArgs = new String[]{"AsciiVideo"};
156         if (passedArgs != null) {
157             PApplet.main(concat(appletArgs, passedArgs));
158         } else {
159             PApplet.main(appletArgs);
160         }
161     }
162 }

Sunday, 26 April 2015

Back to the future for developing processing-3.0a6 in netbeans

More to come when I have time but just to note that if you wish to develop sketches with latest processing this earlier post is interesting again as you have refer to native libraries at run time. See instructions for processing-1.5.1, can't we have jar wrapped binaries anymore (which we had with processing-2.0 and solved the problem)?

Also note sketchWidth, sketchHeight and sketchRenderer methods seem to be required but you can ditch size (that was used previously, now presumably only for use in processing ide, or a at least with pre-processed ie *.pde files).
Here is a general lwjgl article, so its not our processing bros to blame. Update 21 June LWGL stuff no-longer relevant following a return to JOGL.

Sunday, 18 January 2015

Experimenting with processing-3.0a5

For the most part everything just works for me (64 bit linux Mint / Archlinux), but more radical changes are expected before version 3.0 gets released.
Owing to a policy change the sound and video libraries are no longer included in the processing distro.
You will need to install the video library from processing.org this is easiest done from the processing ide, see the Dan Shiffman video on video capture. Rather than install the possibly flaky sound library from processing.org, currently I would recommend that you install the tried and tested minim library (which can also be installed from the processing ide). However if you are on a tablet you might have more joy with the sound library from processing.org (as it appears to be designed with mobile devices in mind). Update 25 January 2015 sound library fixed to work on linux (after I had reported it). Not sure about windows status, latterly processing seems to be very Mac centric, despite Apples determined efforts to KILL java.

Monday, 9 June 2014

Interesting times ahead for processing

If you had only just got used to processing-2 then it might not be too comforting to learn that the development effort is switching to processing-3, who knows what sort of beast that might be? The editor is likely to get beefed up, to be more like PDE X mode (the next generation), it might even be multilingual (as German, French etc). As for scripting modes, the python mode is already pretty well developed (as is javascript), but there is a ruby mode on the horizon, and others have also been promised (coffee-script, available but not over elabourated). PVector it seems might get a re-think (much needed in my view) to enable chaining etc etc. Oh and `Applet` will probably disappear as the base class for PApplet (threading issues on the Mac?). Update 1 July May'be they are having a re-think on chaining of PVector as I see from Ben Frys latest commit they have wound back changes that would support it. It is to be hoped that at least keep copy rather than the unfathomable get!!! Update 28 July 2014, well in some ways that's a bit of a relief, processing-3.0a1 is out and the changes (other than to the ide are very conservative) tested it with ruby processing seemed to work OK apart from one P3D sketch where there was some weird interaction with new ruby-processing bits (size got all weird, extra lines in OPENGL, I can't report it 'cos it uses new ruby-processing functionality too). In some ways it is disappointing, there wasn't a bigger change, a major bump up in version number and the yet changes are much less than 1.5 to 2.0 transition (that caused some pain, but was worth it). Update 30 July 2014 weird thing was a bug I introduced into the elegant_ball sketch, since fixed (but I'm not doing a release for an example bugfix, plus result was 'quite' interesting. Update 31 July 2014, I see from Ben Frys latest commits that vanilla processing has a setVertex(PVector vec) method, but due too overloading of PVector he's implementing a bounds check for the 2D version (don't want to set z when 2D) in principle this seems sensible but it would surely have been better to have Vec2D and Vec3D classes no? Update October 8th 2014, promised radical surgery has started Applet has gone....to be replaced by Surface.

Friday, 7 February 2014

Could the Mad Monk (Ji Gong) come to the rescue of java Applets (for the masses)

Sunday, 27 October 2013

Toxiclibs for the future

Some weeks back on the old processing discussion board, someone asked if he could he still use toxiclibs with the current version of processing. I have always found I could but then I've usually built latest version from source. Just clone the latest source, cd to the ant directory,
ant -f build-all.xml
and your done, pick up the zip file from the dist folder and unzip it in your libraries directory. You might want to move the libraries to the outer folder as well.
Further I've always modified the individual build scripts to use jdk level 1.6 changing.
<property name="lib.jdk.level" value="1.5"/>
<property name="lib.jdk.level" value="1.6"/>

In preparation for processing-2.1 I tried the following:-
<property name="lib.jdk.level" value="1.5"/>
<property name="lib.jdk.level" value="1.7"/>
I found I could successfully build against the latest development core.jar (compiled with jdk7), and toxiclibs runs just fine (and only minor adjustments are needed to run examples, mainly to do with obsoleted OPENGL calls or the need to import iterator). Thus toxiclibs appears to pretty much future proof already, I am looking forward to using java-8 in the near future (particularly with ruby-processing, which should benefit from various changes to the jvm), it would not do, to be stuck with jdk level 1.6 let alone jdk level 1.5 for that matter.


Blog Archive

About Me

My photo
Pembrokeshire, United Kingdom
I have developed JRubyArt a new version of ruby-processing for JRuby- and processing-3.1.1