OpenFrameworks Demo

Nikolaus Gradwohl2008-07-20T20:02:00+00:00

this weekend i have written a little c++ program with openframeworks. This is a framework for writing creative programs. it is heavily inspired by processing.

While still in the prerelease state it has some very interesting features and it is realy fun to code with. To get to the download page one has to register for the mailinglist.

To get started copy the emptyExample folder from the apps/examples folder. in the src folder is a empty testApp.cpp and a testApp.h.

the program i have written draws little yellow squares on the screen, that get scared when they hear a sudden loud noise.

my testApp.h looks like this

#ifndef _TEST_APP
#define _TEST_APP


#include "ofMain.h"
#include "ofAddons.h"

class testApp : public ofSimpleApp{

    public:

        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y );
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased();
        void audioReceived( float *input, int bufferSize, int nChannels );

        int boom;
};

#endif

my testApp.cpp looks like this

#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
    boom = 0;
    ofSetVerticalSync( true );
    ofSetFrameRate( 25 );
    ofSoundStreamSetup(0,1,this);
}   

//--------------------------------------------------------------
void testApp::update(){
}
//--------------------------------------------------------------
void testApp::draw(){
    ofBackground( 0,0,0 );
    int sx = 0;
    int sy = 0;
    if (boom>0) {
        ofSetColor(255,0,0);
        boom = boom -2;
    } else {
        ofSetColor(255,255,0);
    }
    ofFill();
    for ( int x=0; x < 11; x++ ) {
        for ( int y = 0; y < 7; y++ ) {
            if ( boom > 0 ) {
                sx = 10 * ofRandomf();
                sy = 10 * ofRandomf();
            }
            ofRect(sx + x*120 + 20, sy + y*120 + 20, 100, 100);
        }
    }
}

//--------------------------------------------------------------
void testApp::keyPressed  (int key){ 
}

//--------------------------------------------------------------
void testApp::keyReleased  (int key){ 
}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}

//--------------------------------------------------------------
void testApp::mouseReleased(){
}

void testApp::audioReceived (float * input, int bufferSize, int nChannels) {
    int count = 0;
    for( int i=0; i<bufferSize; i++ ) {
        if (input[i] > 0.3 || input[i] < -0.3 ) {
            count++;
        } 
    }
    if ( count > 10 ) {
        boom = 25;
    }
}
Tweet This! submit to reddit Digg! Tags: | no comments | no trackbacks

See also:

feeling watched in openframeworks
osc app using openframeworks
rotating box in openframeworks
running openframeworks on a RaspberryPI
OpenFrameworks boid demo

Trackbacks

Comments

Leave a response

Leave a comment