← Back

ofxExpr

github.com/kasparsj/ofxExpr · @kasparsj
OF 0.11 Algorithms Utilities

mathematical expression parser for strings and ofxGui, based on muParser

0 0 Last commit 11mo ago Created 7y ago

README

ofxExpr openFrameworks addon



<!--- Build status Build status --->

Mathematical expression parser for strings and ofxGui, based on muParser

Precompiled libraries included: For Windows check out libs/muparser/src submodule and follow the instructions in Install.txt file.

Tested with openFrameworks version 0.11.1 (C++ 11)

Supported return value types:

examples



1. arithmetic

float x = 123.0;
float y = 678.0;
float z = 57.0;

ofxFloatExpr expr1;
expr1.set("x  y + 3");
expr1.addVar("x", x, false);
expr1.addVar("y", y);
expr1.addVar("z", z);

cout << "x = " << x << endl; // x = 123
cout << "y = " << y << endl; // y = 678
cout << "z = " << z << endl; // z = 57
cout << expr1.getExpression() << " = " << expr1.get() << endl; // x  y + 3 = 83397


2. trigonometry

float x = 2;
ofxFloatExpr expr2;
expr2.set("sin(x)");
expr2.addVar("x", x);
cout << expr2.getExpression() << " = " << expr2.get() << endl; // sin(x) = 0.909297


3. built-in variables

t = ofGetElapsedTimef();

ofxFloatExpr expr3;
expr3.set("t");
cout << expr3.getExpression() << " = " << expr3.get() << endl; // t = 1.2177


4. built-in functions

float x = 2;
ofxFloatExpr expr4;
expr4.set("rand(x)");
expr4.addVar("x", x);
cout << expr4.getExpression() << " = " << expr4.get() << endl; // rand(x) = 0.37822
cout << expr4.getExpression() << " = " << expr4.get() << endl; // rand(x) = 0.736426

expr4.set("noise(x)");
expr4.addVar("x", x);
cout << expr4.getExpression() << " = " << expr4.get() << endl; // noise(x) = 0.5

Get this addon

HTTPS
SSH