diff options
| author | Tim Redfern <tim@getdrop.com> | 2023-04-19 12:01:10 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2023-04-19 12:01:10 +0100 |
| commit | 28718e114696f1d5d735992c29f8e0b1dd83a90d (patch) | |
| tree | 516190f74c9242d7343a088107ae61fa043546ed /nextus/src/vectorPlugin.cpp | |
| parent | beaeeb0a47d1e4a0b62264263dd319dc49d6a2f9 (diff) | |
WIP some svg stuff working
Diffstat (limited to 'nextus/src/vectorPlugin.cpp')
| -rw-r--r-- | nextus/src/vectorPlugin.cpp | 148 |
1 files changed, 76 insertions, 72 deletions
diff --git a/nextus/src/vectorPlugin.cpp b/nextus/src/vectorPlugin.cpp index 03b7eaa..c87de08 100644 --- a/nextus/src/vectorPlugin.cpp +++ b/nextus/src/vectorPlugin.cpp @@ -53,7 +53,7 @@ void svgPanel::load(string filename){ path.getStrokeColor() ) ); - //shape_selection_durations.push_back(0.0f); + shape_selection_durations.push_back(0.0f); } //strm << " , "; @@ -61,21 +61,13 @@ void svgPanel::load(string filename){ //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); - ofLog()<<"loaded SVG "<<filename<<", "<<segmenters.size()<<" paths"; + select_random_shapes(); + + ofLog()<<"loaded SVG "<<filename<<", "<<segmenters.size()<<" paths"; } else { @@ -83,48 +75,60 @@ void svgPanel::load(string filename){ } } -void svgPanel::select_random_shapes(float duration,bool generate){ - 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; - } +void svgPanel::select_random_shapes(){ + + 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<<" "; } +} + +void svgPanel::update_random_shapes(bool generate=true){ + shape_selection.clear(); + //track how long each shape has been selected and recreate the selection for (int i=0;i<shape_selection_durations.size();i++){ - if (shape_selection_durations[i]>0.0f){ + if (shape_selection_durations[i]>timedelta){ + shape_selection_durations[i]-=timedelta; 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"; - if (generate){ - - //the toggle was pressed - //simulate a button - generate_shapes=false; + cout << timedelta <<": decay selection: "<<shape_selection.size()<<" shapes (" << strom.str() <<") \n"; + */ + if (generate){ 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_durations[selection]=shapes_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"; + */ } - //cout << "random selection: "<<shape_selection.size()<<" shapes (" << strm.str() <<") \n"; } @@ -138,55 +142,55 @@ vector<colourPolyline> svgPanel::getAllLines(){ vector<colourPolyline> svgPanel::getLines(){ vector<colourPolyline> output; - return output; + //if (!use_onset||onset_frame<onset_duration||shapes_randomise){ - if (shapes_randomise){ - //if (framecounter==0){ - // select_random_shapes(); - // framecounter=shapes_duration; - //} - select_random_shapes(shapes_duration,generate_shapes); //from audio !use_onset||onset_frame<onset_duration); - for (auto s:shape_selection){ - if (use_segmenter){ - auto segments=segmenters[s].getSegments(segmenter_number,segmenter_length,phase); - for (auto segment=segments.begin();segment!=segments.end();segment++){ - //output.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); - output.push_back(*segment); - } - } - else { - //output.push_back(colourPolyline(segmenters[s].getPoly(),ofColor(laser_R,laser_G,laser_B))); - output.push_back(segmenters[s].getPoly()); + if (shapes_randomise){ + //if (framecounter==0){ + // select_random_shapes(); + // framecounter=shapes_duration; + //} + update_random_shapes(true); //from audio !use_onset||onset_frame<onset_duration); + for (auto s:shape_selection){ + if (use_segmenter){ + auto segments=segmenters[s].getSegments(segmenter_number,segmenter_length,phase); + for (auto segment=segments.begin();segment!=segments.end();segment++){ + //output.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); + output.push_back(*segment); } } - framecounter--; + else { + //output.push_back(colourPolyline(segmenters[s].getPoly(),ofColor(laser_R,laser_G,laser_B))); + output.push_back(segmenters[s].getPoly()); + } } - else { - for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ - if (use_segmenter){ - auto segments=shape->getSegments(segmenter_number,segmenter_length,phase); - for (auto segment=segments.begin();segment!=segments.end();segment++){ - //output.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); - output.push_back(*segment); - } - } - else { - //output.push_back(colourPolyline(shape->getPoly(),ofColor(laser_R,laser_G,laser_B))); - output.push_back(shape->getPoly()); + framecounter--; + } + else { + for (auto shape=segmenters.begin();shape!=segmenters.end();shape++){ + if (use_segmenter){ + auto segments=shape->getSegments(segmenter_number,segmenter_length,phase); + for (auto segment=segments.begin();segment!=segments.end();segment++){ + //output.push_back(colourPolyline(*segment,ofColor(laser_R,laser_G,laser_B))); + output.push_back(*segment); } } - } - /* - this should happen at output stage? - - if (contour_useColour){ - vector<colourPolyline> newPolys; - for (auto p: output){ - newPolys.push_back(colourPolyline((ofPolyline)p,ofColor(laser_R,laser_G,laser_B))) ; + else { + //output.push_back(colourPolyline(shape->getPoly(),ofColor(laser_R,laser_G,laser_B))); + output.push_back(shape->getPoly()); } - output=newPolys; } - */ - //} + } + /* + this should happen at output stage? + if (contour_useColour){ + vector<colourPolyline> newPolys; + for (auto p: output){ + newPolys.push_back(colourPolyline((ofPolyline)p,ofColor(laser_R,laser_G,laser_B))) ; + } + output=newPolys; + } + */ +//} + return output; }
\ No newline at end of file |
