Sunday, July 06, 2008

Moving over... PostSpectacular is here

As one or the other might have noticed by now, this blog has not gotten a lot of love (or any attention in general) from me for a long, long time now and this will most likely be one of the last posts over here...

The reason for all this silence has been that last autumn I decided to finally take the step I'd been preparing for such a long time and so I'd finally setup my own studio to work more freely, collaborate more, opensource more and generally be able to focus more on interesting computational design projects, be they commercial or artistic.

PostSpectacular is here, along with a new blog and a list of recent projects. I've also nailed down a little manifesto for this new endeavour to help myself and my (new) clients.

Giving interested people more insight into our way of working is also an important part of this new setup and inspired by the manifesto so far I've written up quite detailed documentations (incl. one with a making-of video) for these 4 recent projects in the hope to share & inspire:

Print magazine cover design, August 2008

A generative typographic sculpture realized with Processing and 3D printing

Faber Finds

Created a software solution to generate unique book covers for this new print-on-demand service.

Nokia Friends

Software animation instrument and physics driven character generator.

Advanced Beauty: Enerugii, pt.II

Audio responsive HD motiongraphics piece for this collaborative DVD project.

At this point, I just want to say thanks to everyone who's taken the time to come by here now and in the past and I hope to see you again at the new place! Danke! Btw. At the time of this writing, the new studio website is still a bit rough around the edges, but in true agile manner it's already been running for 10 months on a customized/themed version of DokuWiki and most of the important content is there now..

Tuesday, December 04, 2007

Arduino + Processing London workshop this weekend

Apologies for not posting this any earlier (or any other news for that matter, of which there are plenty): Organized by the lovely folks @, together with Spencer Roberts I'll be co-teaching an H3:Arduino+Processing workshop this weekend (8th/9th December) and would like to point out there are still places available. You should have some basic/intermediate experience with both tools as we will be looking at more "advanced" (yuck, how I hate this word) topics and will try to each have a little interactive project built over the weekend. The workshop space itself is kindly provided by Moving Brands in Shoreditch.

More info and schedule on the workshop website. Ciao.

Tuesday, September 18, 2007

Up & coming in The Netherlands

As usual, a last minute notification (few hours before leaving) about my participation in this year's TodaysArt festival in The Hague, Netherlands.

<>TAG kindly invited me to give 2 lectures about my Processing works in the context of their Information Aesthetics 2 symposium. First I'll be joining Mr. Casey Reas and Aaron Koblin @ Mediamatic in Amsterdam, this Thursday at 2030h.

The Information Aesthetics symposium will then take place at the Spui Theatre, The Hague on Saturday from 1400-1800h. Marius Watz and Manuel Lima (author of Visual Complexity) will also take part in this so am looking ++forward to see what everyone has been up to recently and of course to the discussion about our varied approaches.

Last but not last, I (under the Moving Brands moniker) will be responsible for the re-staging of an adaptation of the KEF Muon audio visualization - this time unfortunately without the Muon speakers & LED floor - but projected in the amazing space of the Richard Meier designed city hall of The Hague. This will be happening throughout Friday and Saturday.

Tuesday, August 21, 2007

Creating weblinks in PDF with iText

Mr. LennyJPG pinged me this morning asking about creating hyperlinks in PDFs generated with Processing. After some digging through the iText javadocs and reading various tutorials it became obvious that Processing's PGraphicsPDF class had to be modified to give us access to the wrapped PdfContentByte instance so that the hyperlink magic can happen. My modified version of Processing's PDF library can be downloaded from here (jar) and there (source). The .jar has to be placed in the /libraries/pdf/library folder inside the Processing root, but please make sure to keep a backup of the original.

The demo below is briefly showing how to create weblinks (here: to various users) and how to position these on the page. All should be pretty self-explanatory. Finally, here's an example PDF generated with this demo.

* iText/Processing PDF weblink demo
* Builds a number of links on the fly and
* positions them randomly on the page.
* CAUTION: This demo requires a modified version of
* Processing's PGraphicsPDF class
* @author: info at toxi dot co dot uk
import processing.pdf.*;
import com.lowagie.text.*;
import com.lowagie.text.pdf.*;

void setup() {
PGraphicsPDF pdf=(PGraphicsPDF)beginRecord(PDF,"test"+(System.currentTimeMillis()/1000)+".pdf");

// draw something in the background
for(int i=0; i < height; i+=10) {

try {
// build hyperlinks for these users
String[] users=new String[] {

for(int i=0; i < users.length; i++) {
// java colours are normalized 0.0 .. 1.0
Color linkCol = new Color(random(1), random(1), random(1));
Chunk c=new Chunk(users[i],FontFactory.getFont(FontFactory.HELVETICA, 14, com.lowagie.text.Font.UNDERLINE, linkCol));
c.setBackground(new Color(0,0,0),5,5,5,5);
// this is using a hacked version of PGraphicsPDF to get access to the PDF content
PdfContentByte cb=pdf.getContent();
ColumnText ct = new ColumnText(cb);
float x=random(width-100);
float y=random(height-100);
ct.setSimpleColumn(new Phrase(c), x,y, x+100, y+50, 16, Element.ALIGN_CENTER);
catch(Exception e) {

// see link below for more info about this method:
void pageSize(com.lowagie.text.Rectangle r, boolean isLandscape, String renderer) {
if (isLandscape) {
else {

Tuesday, July 31, 2007

Using JavaDB and db4o in Processing

Kind of as reply to Tom's mini howto for using SQLite with Processing, but also since I've been dabbling with it myself recently, here's an alternative take on using an embedded database from within Processing (or more generally in Java)...

Mainly due to Java's strong focus on server side development, over the past few years there have been several large scale community efforts to create Java native database engines, which don't rely on underlying C code, are high performant and portable: the essence of the Java way. The other benefit is that such DB engines can be embedded and distributed with your application without requiring any further installation. One such development effort is Apache Derby, a project which started in 1996, swapped owners several times (amongst them IBM) and then became an incubator project at Apache in 2004. Sun also joined the project and has been bundling it as library (under the name JavaDB) as part of the JDK (v6+) since December 2006. So in other words if you have Java6 installed you also should have Derby. But even if you don't (for example Mac users), you can download Derby from here and unzip it to any folder on your hard drive.

The following deals with setting up Processing to work with Derby:
  1. Create a new folder structure /derby/library within Processing's /libraries folder
  2. Copy the file derby.jar from Derby's /lib folder into the newly created folder

Before we can start using the database now we first need to create a new database. Derby comes with its own commandline client "ij" which is located in the /bin directory of the main Derby install dir (If you're going to use this tool more often it would make sense to add this /bin directory to your system path).

Launch ij from the commandline and then create a new database with this command:
ij> connect 'jdbc:derby:/path/to/database;create=true';

Databases are just folders and can be stored anywhere. For example on Windows the path /dev/derby/mydb would refer to C:\dev\derby\mydb...

Next create some a simple table in the new database and add some data:
ij> create table cities (
cityID integer not null primary key,
name varchar(32) not null
insert into cities values(1,'london');
insert into cities values(2,'berlin');
insert into cities values(3,'san francisco');

Given that all worked fine so far we can finally move on to a small Processing demo to query our exciting dataset:
import org.apache.derby.*;
import java.sql.*;

String driver = "org.apache.derby.jdbc.EmbeddedDriver";
String connectID = "jdbc:derby:/derby/testdb";
Connection conn;

void setup() {
try {
catch(SQLException e) {

void query() throws SQLException {
catch(java.lang.ClassNotFoundException e) {

try {
conn = DriverManager.getConnection(connectID);
Statement st=conn.createStatement();
ResultSet results=st.executeQuery("SELECT * FROM cities");
while ({
println("City: "+results.getString("name"));
catch (Exception e) {
finally {
// always make sure we close the connection
if (conn!=null) conn.close();

Now, this is obviously an absolute bare bones demo, however Florian Jennet wrote a little database library last year to hide all these excessive try/catch clauses. Unfortunately he's also hardcoded the database connection string to only work with MySQL and there's no source supplied with the library so one could change it and easily add support for other JDBC drivers... (nudge! :)

Speaking of databases, here's another food for thought. SQLite, MySQL, Apache Derby et al are all based on the relational database model. Java on the other hand is object oriented and as you can see it takes a relative large effort to exchange data between both worlds without any further help. To ease these tasks there're various powerful object relationship mappers available acting as translators between the worlds of objects and that of SQL. Last but not least, native object oriented databases are yet another alternative approach here which is far more aligned with the language. db4o is such an object database and allows you to store and query complex object hierarchies in a most natural (in a Java context) way. For example with db4o you can store and restore the entire state of an application - with just a single line of code. This in turn not just saves you a lot of time and headaches, but also enables building more complex, data intensive applications. If you're interested, the db4o site has a very easy to follow tutorial...