openFrameworks Live Coding Proof of Concept

November 20th, 2008 · 5 Comments · Creative Coding

Live Coding OF Proof of Concept

Recently I promised to write another post on what cool stuff can be done with the openFrameworks-Python binding. Besides the fact that being able to quickly write openFrameworks apps with Python is cool enough actually, Python is an interpreted language and does therefore enable us to execute and change code dynamically — even at runtime. Hence, an obvious purpose for using this feature is live coding.

In order to get us there, modifications need to be made to the original source code of More precisely, the draw function of the testApp class has to be changed to something like this:

def draw(self):
    file = open(oscwd + '/', 'r')
    source =

This code snippet loads the file located in the current working directory, which has previously been stored to a variable called oscwd. is going to contain the actual code responsible for rendering the openFrameworks scene. As you can see on the screenshot you can now start, fire up a code editor (in this case Xcode) to edit and begin live coding. As soon as you save your changes to the file the modified code will be executed in the application.

So far so good, but there are still some issues: for some reason (which I will explain later) the code inside the testApp class has a different Python environment than the surrounding code. This causes stdout / stderr to be redirected into nirvana (what ever you try to put on stdout inside the class will not appear in the shell; errors in your code will not be prompted either). What is more, the os and sys functions do not work properly here. This is the reason why I temporarily stored os.getcwd() in the oscwd variable of the animation module. Finally, the execution of the whole application will be broken as soon as you save with syntax errors (and as mentioned previously, stderr will not be prompted on the shell in this case). Consequently, the whole approach is still quite unstable and should therefore be considered a POC.

Download the live coding POC files (ZIP file, 5.1 MB, requires Mac OS X 10.4.11+ and Python 2.5)

Tags: ··

5 responses so far ↓

  • 1 Maddi  Nov 28, 2008 at 3:46 pm

    It should work to do
    ‘exec source in globals(), locals()’ to get os, sys and everything else from the parent process. I’d put a try/except around the exec too.

  • 2 admin  Nov 30, 2008 at 5:51 pm

    Hey Maddi, did you try this already? Perhaps you’d like to contribute your exact changes back — my time is short at the moment and I consider this thing a community project anyways. (What’s more we cannot assume presently that of is stable from an architectural point of view and thus cannot build more than prototypes..)

  • 3 openFrameworks-0.04-Python Live Coding POC Reloaded  Dec 12, 2008 at 8:38 am

    […] I presented the openFrameworks-Python live coding proof of concept on this blog. Unfortunately, the first version was quite unstable, because code changes introducing […]

  • 4 Maddi  Dec 12, 2008 at 3:12 pm

    I did not try this, but I sure like to take a look at openFramework one of these days πŸ™‚

  • 5 husk  Apr 1, 2009 at 3:40 am

    Hey, very good project, I like it! I tested the python-of-binding and i’m thinking to use it on some project. Does it support all video function from ofVIdeoGrabber and ofVideoPlayer?

© 2013 Tobis Lensing. All rights reserved. Powered by Wordpress — based upon Cutline by Chris Pearson. This page reflects the personal opinion of the author and is in no way linked to institutions the author is working or has worked for. For more information, see the disclaimer and Privacy Policy.