- Mastering openFrameworks:Creative Coding Demystified
- Denis Perevalov
- 336字
- 2021-08-06 16:54:15
Basic utility functions
The last section of the chapter mentions some utility functions, which will be used in examples across the book, or just can be useful in your projects.
ofMap( v, v0, v1, out0, out1 )
: This function performs linear interpolation of a float valuev
from the segment[v0, v1]
to the segment[out0, out1]
. Note, it does not control boundaries ofv
, and just uses the formula (v-v0)/(v1-v0)*(out1-out0) + out0. For controlling boundaries, call this function with the last optional parameter set totrue
:ofMap( v, v0, v1, out0, out1, true )
. Then the result will be clamped to[out0, out1]
.ofClamp( v, v0, v1 )
: This function clamps the float valuev
to the segment[v0, v1]
that is returnsmin( max( v, v0 ), v1 )
.ofRandom( a, b )
: This function generates a pseudo-random number in the segment[a, b]
. (Actually, it returns a value always less than that ofb
).ofNoise ( x )
,ofNoise( x, y )
,ofNoise( x, y, z )
, andofNoise( x, y, z, w )
:These functions return Perlin noise value, see the details in Appendix B, Perlin Noise.ofToString( v )
: This function converts theint
orfloat
valuev
into string-returning valueofToInt( s )
andofToFloat( s )
: These functions convert the strings
intoint
orfloat
returning values respectively.ofGetWidth()
andofGetHeight()
: These functions return the current width and height of the project's screen, in pixels.ofGetElapsedTimef()
: This function returns the value of seconds lapsed from the project's start. This is afloat
value, measured with millisecond accuracy. For example, returned value 123.4 means 123 seconds and 400 milliseconds.ofShowCursor()
andofHideCursor()
: These functions show and hide the mouse cursor.
For printing information into a console window, you can use the standard cout
stream. For example, for printing time from the project's start, use the following code:
cout << "Time: " << ofGetElapsedTimef() << endl;
Here, endl
is a standard constant, which means starting a new line in the console.
推薦閱讀
- Java語言程序設計
- Learning Python Web Penetration Testing
- Node.js+Webpack開發實戰
- Learning PostgreSQL
- 從程序員到架構師:大數據量、緩存、高并發、微服務、多團隊協同等核心場景實戰
- QGIS:Becoming a GIS Power User
- Building RESTful Python Web Services
- Express Web Application Development
- Visual Basic程序設計習題與上機實踐
- 持續集成與持續交付實戰:用Jenkins、Travis CI和CircleCI構建和發布大規模高質量軟件
- Continuous Delivery and DevOps:A Quickstart Guide Second Edition
- Python Penetration Testing Essentials
- 多接入邊緣計算實戰
- Node.js入門指南
- Spark Streaming技術內幕及源碼剖析