Created
September 6, 2017 00:43
-
-
Save aferriss/ebc2cc66c799b781fd0e4ce375ceebfc to your computer and use it in GitHub Desktop.
Smooth points in openframeworks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| static float smooth_dist = 0.0; | |
| vector<ofVec2f> DrawLook::smoothPoints(ofVec2f p, ofVec2f lp, ofVec2f llp, float size){ | |
| vector<ofVec2f> points; | |
| float step = MAX(size / 4, 1.0); | |
| ofVec2f mp1 = lp; | |
| mp1.middle(llp); | |
| ofVec2f mp2 = p; | |
| mp2.middle(lp); | |
| float resolution = 1024.0; | |
| ofVec2f lnp = ofVec2f(0.0,0.0); | |
| for(int j= 0; j < resolution; ++j){ | |
| float progress = j/resolution; | |
| float scl = pow(1.0 - progress, 2.0); | |
| ofVec2f n1 = mp1; | |
| n1 *= (scl); | |
| float scl2 = 2.0 * (1.0 - progress) * progress; | |
| ofVec2f n2 = lp; | |
| n2 *= (scl2); | |
| float scl3 = progress * progress; | |
| ofVec2f n3 = mp2; | |
| n3 *= (scl3); | |
| ofVec2f newp = (n1 + n2) + n3; | |
| if(j > 0 ){ smooth_dist += newp.distance(lnp); } | |
| if( smooth_dist >= step){ | |
| smooth_dist -= step; | |
| points.push_back(newp); | |
| } | |
| lnp = newp; | |
| } | |
| return points; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment