diff options
| author | Tim Redfern <tim@getdrop.com> | 2018-01-18 23:39:41 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2018-01-18 23:39:41 +0000 |
| commit | 7f2fb4dc45faa9d87906b9e1006be851a5549534 (patch) | |
| tree | 5e56252741406021e6456e18b7c736bdc1b49fb0 /drawing/src/ofApp.cpp | |
| parent | 3e7861432b655075890ad3ad4efaf57881188839 (diff) | |
ofxClipper
Diffstat (limited to 'drawing/src/ofApp.cpp')
| -rw-r--r-- | drawing/src/ofApp.cpp | 56 |
1 files changed, 41 insertions, 15 deletions
diff --git a/drawing/src/ofApp.cpp b/drawing/src/ofApp.cpp index 43069d2..e888d4d 100644 --- a/drawing/src/ofApp.cpp +++ b/drawing/src/ofApp.cpp @@ -9,18 +9,24 @@ void ofApp::setup(){ vector <ofPath> paths= svg.getPaths(); for (int i=0;i<paths.size();i++){ + vector <ofPolyline> outlines= paths[i].getOutline(); + for (int j=0;j<outlines.size();j++){ + segmenters.push_back(lineSegmenter(outlines[j])); + } + } - paths[i].setMode(ofPath::COMMANDS); + cout << "Drawing: found " << paths.size() << " paths with " << segmenters.size() << " shapes" <<std::endl; + svg.load("lorenzo.svg"); + paths= svg.getPaths(); + for (int i=0;i<paths.size();i++){ vector <ofPolyline> outlines= paths[i].getOutline(); - for (int j=0;j<outlines.size();j++){ - segmenters.push_back(lineSegmenter(outlines[j])); + mask.push_back(outlines[j]); } - } - cout << "Found " << paths.size() << " paths with " << segmenters.size() << " shapes" <<std::endl; + cout << "Mask: found " << paths.size() << " paths with " << mask.size() << " shapes" <<std::endl; numsegments=1; coverage=0.5; @@ -33,8 +39,9 @@ void ofApp::setup(){ //-------------------------------------------------------------- void ofApp::update(){ + clipper.Clear(); - + clipper.addPolylines(mask, ClipperLib::ptClip); } @@ -44,34 +51,53 @@ void ofApp::draw(){ ofBackground(0,0,0); ofSetColor(255,255,255); - glTranslatef(-80,-130,0); - int segmentsdrawn=0; + int pointsdrawn=0; + + float phase=fmod(ofGetElapsedTimef()/2,1); switch (mode){ case 0:{ - float phase=fmod(ofGetElapsedTimef(),1); - - - for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ auto segments=shape->getSegments(numsegments,coverage,phase); for (auto segment=segments.begin();segment!=segments.end();segment++){ segment->draw(); - segmentsdrawn++; + segmentsdrawn+=1; + pointsdrawn+=segment->size(); } } + break; } case 1:{ + vector <ofPolyline> shapes; + for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ + auto segments=shape->getSegments(numsegments,coverage,phase); + for (auto segment=segments.begin();segment!=segments.end();segment++){ + shapes.push_back(*segment); + } + } + clipper.addPolylines(shapes,ClipperLib::ptSubject); + vector<ofPolyline> clipped = clipper.getClipped(ClipperLib::ctIntersection); + segmentsdrawn=clipped.size(); + for (auto& clip: clipped) + { + clip.draw(); + pointsdrawn+=clip.size(); + } + } + case 2:{ int w=ofRandom(1000); segmenters[w%segmenters.size()].draw(); + segmentsdrawn=1; + pointsdrawn+=segmenters[w%segmenters.size()].size(); + break; } } std::stringstream strm; - strm << "segments: "<<segmentsdrawn; + strm << "segments: "<<segmentsdrawn<< " points: "<<pointsdrawn; ofSetWindowTitle(strm.str()); mainOutputSyphonServer.publishScreen(); @@ -115,7 +141,7 @@ void ofApp::keyReleased(int key){ break; } case 'p':{ - mode=(mode==1?0:1); + mode=(mode+1)%3; break; } } |
