P5 "constrain" equivalent in ofx

What is the constrain in Processing equivalent in Openframeworks…???

http://processing.org/reference/constrain-.html

thanks,
debashish

I’m not sure if there is a built-in constrain method in OF, but you could easily write your own with just a few if statements like so:

float myApp::constrain(float val, float min, float max){
if(val < min){
return min;
}
else if(val > max){
return max
}
return val;
}

The function is called ofClamp
http://www.openframeworks.cc/documentation/math/ofMath.html#ofClamp

1 Like

Hey, thanks a lot for the reply!

Just wanted to ask if there is some equivalent table for people who are moving from p5 to ofx…

thanks in advance :slight_smile:

This might be a good place to get started.
http://www.openframeworks.cc/tutorials/firstSteps/002-openFrameworks-for-processing-users.html

Most of the core functions in ofx don’t carry any docs or explanation, for eg., I was trying to lookout for the explanation of ofSetVerticalSync.

Please do guide me!

Thanks in advance…