Tag:

I’ve just learned some handy tricks about packaging Processing-based applications with OpenGL for deployment on Mac OS X. As it turns out, it’s remarkably easy to do on a PC if you use Processing’s own application export as a template. My thanks to Ben Fry for the tip (and also for all the other hard work he’s put into Processing…)

Create a sketch called “Dummy” in the Processing GUI. If your final application will use OpenGL, make sure that “Dummy” does as well. Export using “Export as application”. This produces several folders, of which only “application.macosx” is of interest. This has a “Dummy.app” subfolder which is the actual MacOS application. It’s not a single file, but rather a folder structure that on a Mac shows up as a clickable application. Change the name of “Dummy.app” to whatever name you want, keeping the magic “.app” extension.

In “Contents” you will find a file called “Info.plist”. This contains various parameters controlling your Java application, bundled as pairs of <key> and <string>. Make sure that “MainClass” string is the full name of your main class (including package name if any). Change all instances of “Dummy” to the name of your application. You can also tweak a bunch of other options at will.

If you have JAR files that you need to add, place them in the subfolder “Contents\Resources\Java”. It should already contain core.jar as well as the OpenGL-related JARs and jnilib libraries if you exported Dummy with OpenGL imported. You will need to include the new JARs in the “ClassPath” string found in “Info.plist”.

If all changes have been done correctly, you should now have a runnable application. Copy it to a Mac for testing.

For some icing on the cake (and as an alternative to present mode), you can hide the dock and menu bar on application start. Add the following lines to the <dict> section of “Info.plist”:

LSUIPresentationMode
4

Thanks to Vitaflo for his post on the Processing Forums for this tip.

If you compile your code including the Processing source in an IDE like Eclipse, you can simply replace core.jar with your own as long as it contains all the usual Processing class files. I’ve made a few small changes to the PApplet class, so I prefer this option to the standard JAR file.

This is particularly pertinent if you want your OpenGL apps to be anti-aliased on Mac OS, since smooth() does not always turn it on. The solution is to make an alteration to PGraphicsOpenGL using the GLCapabilities class. Read Mike Creighton's post on the Processing forums for the details.

1 Comment »

No, I’m not talking about Christmas ornaments. I just came up with a quick hack to turn off the window frame from inside Processing. See this thread on the Processing forums to know why this is useful.

When running in the IDE the sketch runs as an applet, so it can’t use the “–present” command line switches available to applications because init() is called instead of main(). My hack simply overrides the default init(), sets the frame to be undecorated and then calls the regular PApplet.init().

Update: Setting the location of the window needs to happen in setup(), not init().

import processing.opengl.*;

void setup(){
  size(400,400,OPENGL);
  background(0);
  frame.setLocation(0,0); // needs to be in setup(), not init()
}

void draw(){
  stroke(255);
  line(0,0,200,200);
}  

public void init() {
  frame.setUndecorated(true); // works.

  // call PApplet.init() to take care of business
  super.init();
}

4 Comments »

Some assorted updates and snippets

  • Processing is now up to version 0121. This fixes several bugs, including fixing modelX/Y/Z(), issues with createGraphics() and font problems. As always, read the revisions.txt for information.
  • Daniel Shiffman has updated his Moviemaker library for Processing. It’s a neat little lib that allows direct Quicktime export from Processing. I have used it on several projects with good results, it saves you from having folders with 5000+ individual frames and having to prerender movies with After Effects. Just remember to use Quicktime Animation codec for lossless compression…
  • Sun has GLP'ed Java, finally making it an Open Source platform.
  • Our good friend and unrecognized genius Andreas Schlegel has released a new (and very good-looking) GUI library for Processing: ControlP5. He has even provided drag-n-drop functionality. See the demo for general shock and awe.

No Comments »

I’m currently writing a monster application doing indexing of feeds from blogs, del.icio.us, Flickr, Digg etc. It’s been a bit of a learning curve, but using the excellent and comprehensive Rome library has made it a great deal easier than it might otherwise have been. Rome handles Atom feeds as well as the various confusing RSS variants.

Making sense of feeds is often tricky, as different publishers can use various tags in different ways, or even add their own by introducing custom namespaces. The use of namespaces (which Rome supports through a plugin system) is a promising way of adding custom information, but not without its problems.

Having completed indexing of Flickr, del.icio.us and plain vanilla feeds, I turned to Digg feeds. Imagine my surprise to find out that not only is their advertised namespace (http://digg.com/docs/diggrss/) in fact offline, but they don’t even use it properly in their main RSS feeds.

http://digg.com/rss/containerscience.xml correctly specifies xmlns:digg=”http://digg.com/docs/diggrss/”, but http://digg.com/rss/index.xml specifies xmlns:digg=”docs/diggrss/”. And that just happens to be their main RSS feed. I know it seems niggling to complain, but it messes with the Module I’ve written to handle their tags and seems a tad careless. Oh well, guess I’ll just skip that feed.

More information about Rome, Digg etc:

2 Comments »

This is a simple variant to the built-in saveStrings() method in Processing. It allows you to write strings to a GZIP compressed file instead of a plain text file. Very useful when writing text-based data files that add up to a few megabytes.

Source code - saveStringsGZIP.pde
// saveStringsGZIP.pde
// Marius Watz - http://workshop.evolutionzone.com
//
// Code for saving an array of strings to a GZIP compressed file.
// Based on Processing's built-in saveStrings() method.

// Java classes needed for file I/O.
import java.io.*;
import java.util.zip.GZIPOutputStream;

void setup() {
  String [] s=new String[2000];
  for(int i=0; i< s.length; i++) s[i]=nf(i,50);
  saveStringsGZIP("test.txt",s);
}

// Based on code from processing.core.PApplet, by the Processing team.
public void saveStringsGZIP(String filename, String strings[]) {
  try {
    String location = savePath(filename+".gz");
    GZIPOutputStream fos =
      new GZIPOutputStream(new FileOutputStream(location));
    PrintWriter writer =
      new PrintWriter(new OutputStreamWriter(fos));
    for (int i = 0; i < strings.length; i++)
      if(strings[i]!=null) writer.println(strings[i]);
    writer.flush();
    fos.close();
  } catch (IOException e) {
    e.printStackTrace();
    throw new RuntimeException("saveStringsGZIP() failed: "
      + e.getMessage());
  }
}

No Comments »

I found a simple tutorial over on Java Practices that demonstrated the use of the system clipboard for transferring text between applications using copy / paste. I’m using it to copy color values from an improved version of SimpleColorPicker.pde.

The CopyPaste class described in the code can be dropped into any Processing sketch to provide access to the clipboard.

Source code - CopyPasteTool.pde

Read the rest of this entry »

4 Comments »

Here is the code for a simple Processing GUI utility for editing color palettes. It generates gradients given a start and end color. It will print palettes as hex strings and RGB triplets, change the “prefix” and “suffix” variables to turn the output into readymade code.

I whipped this up to make it easy to make decent color combos for a current project I'm working on. It could do with a few more features, like a 2D RGB color field to choose from and the ability to save and maybe even load files. It feeds into a color library I use, maybe I’ll make that available at some point to make it a bit more useful.

Source code - SimpleColorPicker.pde

Read the rest of this entry »

3 Comments »

This little code piece implements a Timer class which takes a duration and countdown, and returns a value in the range [0..1] depending on how much of the specified time has elapsed. The variable “fract” gives the state of the timer, with a value of 0 representing a state in which the timer has not started (i.e. still in countdown interval). A value of 1 means that the countdown is complete and the time specified as duration has elapsed. A fractional value represents how far into the time interval the program has reached.

This is useful for animation in absolute time, regardless of frame rate. The timer’s update() function must be called before using the value contained in the “fract” variable.

Source code - Timer.pde

Read the rest of this entry »

No Comments »

Robert Hodgins just posted on the Processing forums asking about techniques for mapping colors in an image to a pre-specified palette. This process is known as color quantization, and is what any image software does when it saves a GIF. It consists in mapping a potentially very large number of unique colors in a RGB image to a limited number of colors (for GIF, typically some multiple of 2, i.e. 64, 128, 256 etc.)

I had to find a way to do quantization it for a project where I needed to output GIFs several years ago. At the time I tried some code for NeuQuant neural net quantization, which didn’t work for me. However, Mario Klingemann posted a NeuQuant Processing example (with code) a while back which does it successfully.

The solution I ended up using was the Java Imaging Utilities (JIU) library, an Open Source library written by Marco Schmidt. It has a number of quantization implementations, such as ArbitraryPaletteQuantizer, OctreeColorQuantizer and PopularityQuantizer. The only drawback is that JIU uses an internal custom RGBImage class, rather than the standard java.awt.BufferedImage. For use with Processing, one will need to convert the image before quantizing it.

No Comments »