@@ -8,24 +8,24 @@ void ofApp::setup(){
88 }else {
99 shader.load (" shadersGL2/shader" );
1010 }
11-
11+
1212 brushImage.load (" brush.png" );
1313 // change the image to draw from the center
1414 // the default is from top left
1515 brushImage.setAnchorPercent (0 .5f , 0 .5f );
16-
16+
1717 textures.resize (5 );
1818 for ( int i = 0 ; i < textures.size (); i++ ){
1919 ofLoadImage (textures[i], " tex" +ofToString (i,0 )+" .jpg" );
2020 }
21-
21+
2222 bBrushDown = false ;
23-
23+
2424}
2525
2626// --------------------------------------------------------------
2727void ofApp::update (){
28-
28+
2929 // check to see if we need a new fbo size
3030 // if the window size changes or the fbo is not allocated, we can catch it here and reallocate
3131 if ( !maskFbo.isAllocated () || maskFbo.getWidth () != ofGetWidth () || maskFbo.getHeight () != ofGetHeight () ){
@@ -36,7 +36,7 @@ void ofApp::update(){
3636 maskFbo.begin ();
3737 ofClear (0 ,0 ,0 ,255 );
3838 maskFbo.end ();
39-
39+
4040 drawMesh = ofMesh::plane (maskFbo.getWidth (), maskFbo.getHeight () );
4141 // the plane has tex coords from 0 - 1, but we need tex coords from 0 -> maskFbo.getWidth()
4242 auto & texCoords = drawMesh.getTexCoords ();
@@ -45,11 +45,11 @@ void ofApp::update(){
4545 for ( auto & tc : texCoords ){
4646 tc = maskFbo.getTexture ().getCoordFromPercent (tc.x , (1.0 -tc.y ));
4747 }
48-
48+
4949 // lets reload the font at a size in relation to width or height
5050 ofTrueTypeFont tf;
51- tf.load (" Batang.ttf" , MIN (maskFbo.getWidth (), maskFbo.getHeight ()) / 2 , true , true , true );
52-
51+ tf.load (" Batang.ttf" , std::min (maskFbo.getWidth (), maskFbo.getHeight ()) / 2 , true , true , true );
52+
5353 oLine.clear ();
5454 // pull out the polylines of the O character for later use
5555 // getCharacterAsPoints returns an ofPath
@@ -60,7 +60,7 @@ void ofApp::update(){
6060 for ( auto op : opolys ){
6161 oLine.addVertices ( op.getVertices () );
6262 }
63-
63+
6464 fLine .clear ();
6565 // pull out the polylines of the F character for later use
6666 opath = tf.getCharacterAsPoints (' F' , true , false );
@@ -75,7 +75,7 @@ void ofApp::update(){
7575void ofApp::draw (){
7676
7777 ofSetColor (255 );
78-
78+
7979 // ----------------------------------------------------------
8080 // draw the brush into the fbo with the position based on the polylines derived from the font
8181 maskFbo.begin ();
@@ -87,21 +87,21 @@ void ofApp::draw(){
8787 // store the elapsed time in a variable for later use
8888 float elapsedTime = ofGetElapsedTimef ();
8989 float deltaTime = ofClamp ( ofGetLastFrameTime (), 1 .f / 1000.0 , 1 .f / 5 .0f );
90-
90+
9191 float mouseXPercent = ofMap ( ofGetMouseX (), 0 , ofGetWidth (), 0.05 , 1.0 , true );
9292 eTimeCounter += deltaTime * mouseXPercent;
93-
93+
9494 float offset = ofMap ( ofGetMouseY (), 10 , ofGetHeight ()-10 , 0 , 100 , true );
95-
95+
9696 float polylinePercent = ofWrap ( eTimeCounter, 0 , 1 );
9797 float findex = oLine.getIndexAtPercent (polylinePercent);
98-
98+
9999 auto position = oLine.getPointAtPercent ( polylinePercent );
100100 auto normal = oLine.getNormalAtIndexInterpolated (findex);
101101 normal *= sin ( elapsedTime * 13 .4f ) * cos (elapsedTime * 2 .4f );
102102 normal.z = 0.0 ;
103103 position += normal * offset;
104-
104+
105105 ofPushMatrix ();
106106 // translate to the center of the fbo //
107107 ofTranslate ( maskFbo.getWidth ()/2 ., maskFbo.getHeight () / 2 . );
@@ -110,15 +110,15 @@ void ofApp::draw(){
110110 ofTranslate ( -oLine.getBoundingBox ().getWidth ()*0 .75f , 0 .0f );
111111 brushImage.draw (position.x , position.y , brushSize, brushSize);
112112 ofPopMatrix ();
113-
114-
113+
114+
115115 findex = fLine .getIndexAtPercent (polylinePercent);
116116 position = fLine .getPointAtPercent ( polylinePercent );
117117 normal = fLine .getNormalAtIndexInterpolated (findex);
118118 normal *= sin ( elapsedTime * 9 .4f ) * cos (elapsedTime * 5 .4f );
119119 normal.z = 0.0 ;
120120 position += normal * offset;
121-
121+
122122 ofPushMatrix ();
123123 // translate to the center of the fbo //
124124 ofTranslate ( maskFbo.getWidth ()/2 ., maskFbo.getHeight () / 2 . );
@@ -127,7 +127,7 @@ void ofApp::draw(){
127127 ofTranslate ( fLine .getBoundingBox ().getWidth ()*0 .75f , 0 .0f );
128128 brushImage.draw (position.x , position.y , brushSize, brushSize);
129129 ofPopMatrix ();
130-
130+
131131 maskFbo.end ();
132132
133133 // ----------------------------------------------------------
@@ -144,7 +144,7 @@ void ofApp::draw(){
144144 brushImage.draw (brushImageX, brushImageY, brushSize, brushSize);
145145 maskFbo.end ();
146146 }
147-
147+
148148 // ----------------------------------------------------------
149149 // HERE the shader-masking happens
150150 shader.begin ();
@@ -169,9 +169,9 @@ void ofApp::draw(){
169169 ofTranslate (ofGetWidth ()/2 , ofGetHeight ()/2 );
170170 drawMesh.draw ();
171171 ofPopMatrix ();
172-
172+
173173 shader.end ();
174-
174+
175175 // ----------------------------------------------------------
176176 float drawStringY = 0 ;
177177 ofDrawBitmapStringHighlight (" Drag the Mouse to draw. Mode (e): " +string (bEraser?" eraser" :" brush" ), 15 ,drawStringY+=15 );
@@ -217,7 +217,7 @@ void ofApp::keyReleased(int key){
217217
218218// --------------------------------------------------------------
219219void ofApp::mouseMoved (int x, int y){
220-
220+
221221}
222222
223223// --------------------------------------------------------------
@@ -246,6 +246,6 @@ void ofApp::gotMessage(ofMessage msg){
246246}
247247
248248// --------------------------------------------------------------
249- void ofApp::dragEvent (ofDragInfo dragInfo){
249+ void ofApp::dragEvent (ofDragInfo dragInfo){
250250
251251}
0 commit comments