I’ve been messing around with python extensions lately and thought it would be a neat idea to create python bindings to openframeworks for some rapid development. You can test ideas out quickly, instead of having to compile over and over. Since the functions are bindings performance is good, good enough to code your final projects in python! Of course C++ is faster but so far I havn’t noticed a slowdown in performance. On the examples the frames per second of the C++ version is almost exactly the same as the Python version. Here is some example code and output:
There are some things that need to be fixed… audioRequested/audioReceived acts very wierdly… causing python to crash. I believe this is because ofSoundStream is non-blocking but maybe I’ve made a mistake in the extension… the only solution I see for now would be changing it to blocking, just like the other audio/video libraries. Pretty much everything else works.
Who’s interested? I’ll release it if enough people want it. First I gotta fix some bugs but overall its pretty functional.
The only prerequisite is of course python. The package binds openframeworks and thus all the libraries it uses.
Example program (third screenshot)
from openframeworks import *
import math
class testApp(ofSimpleApp):
def setup(self):
ofBackground(0,0,0)
self.counter = 0.0
self.spin = 0.0
self.spinPct = 0.0
def update(self):
self.counter = self.counter + 0.029;
self.spinPct = self.spinPct * 0.99
self.spin += self.spinPct
def draw(self):
x = 0; y = 0; R = 90.0; r = 50.0; O = 80.0
ofSetColor(255,255,255)
for i in range(1,800,1):
xPct = i*self.mouseX*0.0001
yPct = i*self.mouseY*0.0001
xPct += self.spin * 0.002
yPct += self.spin * 0.003
if self.mouseX:
r = self.mouseX/10.0
O = self.mouseY/10.0
x = (R+r)*math.cos(xPct) \
- (r+O)*math.cos(((R+r)/r)*xPct)
y = (R+r)*math.sin(xPct) \
- (r+O)*math.sin(((R+r)/r)*xPct)
ofRect(600 + int(x), 320 + int(y), 2, 2);
for i in range(0,20):
ofSetColor(255-i*10, 255-i*20,0)
ofLine(0,i*4, ofGetWidth(), i*4);
def mouseMoved(self,x,y):
self.spinPct += y*0.01
self.spinPct += x*0.01
ofSetupOpenGL(800,700, OF_WINDOW)
ofRunApp(testApp())
As you can see everything is pretty much identical except for the python flavor.