Book Image

OpenFrameworks Essentials

Book Image

OpenFrameworks Essentials

Overview of this book

Table of Contents (19 chapters)
openFrameworks Essentials
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

Mathematical, timer, and conversion functions


The mathematical, timer, and conversion functions were described in Chapter 6, Animating Parameters, and Chapter 7, Distributed and Physical Computing with Networking and Arduino, and are collected in this table:

Function

Description

ofMap( x, 0, 1, 2, 3 )

This linearly maps the float x from segment [0,1] to segment [2,3].

ofMap( x, 0, 1, 2, 3, true )

This linearly maps the float x from the segment [0,1] to the segment [2,3], clamping the output value to the [2,3] range (it occurs when x is not in segment [0,1]).

ofClamp( x, 0, 1 )

This clamps the float x to the range [0,1].

ofInRange( x, 0, 1 )

This returns true if the float x lies in the segment [0,1] and returns false in the opposite case.

ofToString( 0.5 )

This converts a numeric value (integer or float) to a string.

ofGetElapsedTime()

This is the number of seconds elapsed from the application start; the returned value is float.

ofNoise( x )

This is the Perlin noise value for float x.

ofToFloat( "0.5" )

This converts a string to a float number.

ofToInt( "5" )

This converts a string to an integer.

vector<string> list = ofSplitString( "aa;bb;cc;dd", ";" );

This splits a string into an array of strings. The first argument is the string, and the second argument is the delimeter. In our example, the resulting array list will consist of the four elements:

list[0] = "aa"

list[1] = "bb"

list[2] = "cc"

list[3] = "dd"