diff options
Diffstat (limited to 'gui/src/ofApp.cpp')
| -rw-r--r-- | gui/src/ofApp.cpp | 79 |
1 files changed, 70 insertions, 9 deletions
diff --git a/gui/src/ofApp.cpp b/gui/src/ofApp.cpp index 6227686..6d90c47 100644 --- a/gui/src/ofApp.cpp +++ b/gui/src/ofApp.cpp @@ -84,11 +84,12 @@ void ofApp::setup(){ drawgui.add(laser_B.setup("blue", 140, 0, 255)); drawgui.add(video_speed.setup("playback speed", 1.0, 0.0, 3.0)); drawgui.add(shapes_randomise.setup("randomise shapes", true)); - drawgui.add(shapes_amount.setup("shapes amount", 0.2, 0.0, 0.8)); - drawgui.add(shapes_duration.setup("shape duration", 5, 0, 25)); + drawgui.add(shapes_amount.setup("shapes amount", 0.2, 0.0, 1.0)); + drawgui.add(shapes_duration.setup("shape duration", 5.0, 0, 10.0)); drawgui.add(use_mask.setup("use mask", true)); drawgui.add(invert_mask.setup("invert mask", false)); drawgui.add(use_segmenter.setup("use segmenter", false)); + drawgui.add(colour_segmenter.setup("colour segmenter", false)); drawgui.add(segmenter_speed.setup("segmenter speed", 0.2, -1.0, 1.0)); drawgui.add(segmenter_length.setup("segmenter length", 0.2, 0.0, 1.0)); drawgui.add(segmenter_number.setup("segmenter number", 1, 1, 8)); @@ -751,10 +752,11 @@ void ofApp::drawOutput(ofEventArgs & args){ } case SVG_outlines:{ if (shapes_randomise){ - if (framecounter==0){ - select_random_shapes(); - framecounter=shapes_duration; - } + //if (framecounter==0){ + // select_random_shapes(); + // framecounter=shapes_duration; + //} + select_random_shapes(shapes_duration); for (auto s:shape_selection){ if (use_segmenter){ auto segments=segmenters[s].getSegments(segmenter_number,segmenter_length,phase); @@ -1072,7 +1074,48 @@ void ofApp::windowResized(int w, int h){ } -void ofApp::select_random_shapes(){ +float last_frame_time=0.0f; + +void ofApp::select_random_shapes(float duration){ + float timedelta=ofGetElapsedTimef()-last_frame_time; + last_frame_time=ofGetElapsedTimef(); + //track how long each shape has been selected + for (int i=0;i<shape_selection_durations.size();i++){ + if (shape_selection_durations[i]>0.0f){ + shape_selection_durations[i]=shape_selection_durations[i]-timedelta; + } + } + + shape_selection.clear(); + + for (int i=0;i<shape_selection_durations.size();i++){ + if (shape_selection_durations[i]>0.0f){ + shape_selection.insert(i); + } + } + std::stringstream strom; + for (auto& s:shape_selection){ + strom << s <<":"<<shape_selection_durations[s]<<" "; + } + + //cout << timedelta <<": decay selection: "<<shape_selection.size()<<" shapes (" << strom.str() <<") \n"; + + + while (shape_selection.size()<(segmenters.size()*shapes_amount)){ + int selection=rand()%segmenters.size(); + if (shape_selection.find(selection)==shape_selection.end()){ + shape_selection_durations[selection]=duration+ofRandom(1.0f); + shape_selection.insert(selection); + } + } + std::stringstream strm; + for (auto& s:shape_selection){ + strm << s <<":"<<shape_selection_durations[s]<<" "; + } + //cout << "random selection: "<<shape_selection.size()<<" shapes (" << strm.str() <<") \n"; +} +/* +void ofApp::old_select_random_shapes(){ shape_selection.clear(); while (shape_selection.size()<(segmenters.size()*shapes_amount)){ int selection=rand()%segmenters.size(); @@ -1086,6 +1129,7 @@ void ofApp::select_random_shapes(){ } //cout << "randomly selected (" << strm.str() <<") \n"; } +*/ //-------------------------------------------------------------- void ofApp::dragEvent(ofDragInfo dragInfo){ @@ -1112,6 +1156,7 @@ void ofApp::dragEvent(ofDragInfo dragInfo){ if (imagepaths.size()){ segmenters.clear(); + shape_selection_durations.clear(); for (auto& path:imagepaths){ path.setPolyWindingMode(OF_POLY_WINDING_ODD); @@ -1121,12 +1166,28 @@ void ofApp::dragEvent(ofDragInfo dragInfo){ outline.simplify(contour_simplify); strm << outline.size() << " "; segmenters.push_back(colourLineSegmenter(outline,path.getStrokeColor())); + shape_selection_durations.push_back(0.0f); } + strm << " , "; } - cout << "SVG: found " << imagepaths.size() << " paths with " << segmenters.size() << " shapes [ " << strm.str() << " ]" <<std::endl; - select_random_shapes(); + std::stringstream strom; + + shape_selection.clear(); + while (shape_selection.size()<(segmenters.size()*shapes_amount)){ + int selection=(int)ofRandom(0,segmenters.size()); + shape_selection.insert(selection); + } + for (auto s:shape_selection){ + float spawn=(ofRandom(0,(float)shapes_duration)); + shape_selection_durations[s]=spawn; + strom << s << ":"<<spawn<<" "; + } + last_frame_time=ofGetElapsedTimef(); + //cout << "SVG: selected paths [ "<<strom.str() << " ]" <<std::endl; + //cout << "SVG: found " << imagepaths.size() << " paths with " << segmenters.size() << " shapes [ " << strm.str() << " ]" <<std::endl; + //select_random_shapes(shapes_duration); } } |
