Example Source Code

Beginners level

Bouncing Balls

How to have many bouncing balls on the screen. Learn about variables, conditions, loops, functions, classes/structs, objects, arrays, ofGetWidth, ofGetHeight, ofSetBackgroundAuto, ofSetColor, ofSetFrameRate, ofInRange, ofRect, ofImage, ofSoundPlayer.

VideoPlayer frames

This example shows the frames of a video side by side, row by row.


Different ways of writing debug information to the console window: printf, cout, ofLog.

Using the ofxManyMouse addon

This example shows you how to use an openFrameworks addon. The addon in this example lets you read values from separate mouse devices.

Smoothing edges / anti-aliasing

This example shows you how to enable smoothing. First with ofEnableSmoothing but since that function currently only works for lines another method is introduced which enables you to also smooth circles and other shapes.

Alpha trail

This example shows how to achieve a kind of motion blur effect in your openFrameworks application by partially clearing the background.

Lissajous Curve

How to draw a simple mathematical function.

Dynamic arrays 'std::vector'

This example gives an introduction on the std::vector of C++. This is a very powerful way of storing multiple objects in an dynamic array.

GUI's - Buttons, sliders etc.

How to create graphical user interface objects like buttons, sliders, checkboxes with the ofxSimpleGuiToo addon.

Augmented Reality

This example shows how to use the ofxARToolkitPlus addon for tracking physical markers in 3D to manipulate a 3D object on your screen.

Flocking - bird like behavior

This example introduces the ofxFlocking addon for creating autonomous agents with bird-like behavior.

Color Tracking with OpenCV

How to use the ofxOpenCv addon and so some simple color tracking.

Analyze webcam pixels to create a vector field

This example shows how to create a vector field based on the brightness of an image from the webcam. The vector field is displayed in the HSB color space with the ofxSetColorHSB function.

Export to PDF

How to export to PDF from openFrameworks using the ofxCairo addon to a high resolution vector based PDF.

ofx3DUtils addon

How to draw 3D objects, use cameras and apply lighting with the ofx3DUtils addon.

View source

Texture Coordinates

This example shows how map the pixels of a texture to the vertices of a shape.

View source

VideoSaver example

How to save the output of your openFrameworks application as a Quicktime movie using the ofxQtVideoSaver addon.

Cloth physics

Make your particles believe they are part of the same piece of fabric. This example introduces particles and the springs in between them to create cloth-like behavior


How to use the WiiMote via OSCulator & ofxOSC in openFrameworks.

Apply a texture to a sphere

This example shows how to draw a texture on a sphere using gluSphere.

Pizza slices

How to draw textured pizza slices or pie charts.

Points on a sphere

This example shows how to distribute points randomly on a sphere.


How to use ofNoise to create random but smooth in multiple dimensions.

Transparent sphere with ofxArcBall

This example shows how to use the ofxArcBall addon for rotating a sphere with the mouse as well as how to draw several transparent spheres inside of each other which creates a nice depth effect. 


Textured sphere with bumpmap

This example shows how to load a texture on a sphere and apply a displacement shader on the vertices.

Rotating pixels of an image

One might want to rotate the pixel data of an ofImage or ofVideoPlayer and save this under another name or use it to feed it for example to an OCR client like ofxTesseract. This example shows some ways to manipulate the pixel data of an image.

Counting and sorting text

This example shows how to count words in a textfile using std::map. The example is a bit complicated because it also strips html and sorts the words by the number of occurrences.

Color conversion RGB / HSB

This example shows how to convert from the Red/Green/Blue palette to Hue/Saturation/Brightness and vise versa.

RGB cube with ofMesh and ofVbo

This is a kind of freaky example showing how to draw a RGB cube using ofMesh and ofVbo.

HSB Cylinder

This example shows a HSB color cylinder using ofMesh and addTriangle.

Linear HSB gradient with ofColor::fromHsb

This example shows ofColor::fromHsb and ofMap to create a colorpicker with hue in horizontal direction, saturation in the upper half of the vertical direction and brightness in the lower part.

Radial HSB gradient

This example shows how to create a radial HSB gradient / colorpicker using ofDist, atan2, ofMap, ofImage.setColor and ofColor::fromHsb.

4 different HSB Gradients

This example shows how to toggle between four different gradient functions. Use the 1..4 keys on the keyboard so select another gradient.

Rick Companje,
20 feb. 2011 11:31