From 835ce29a83b134b037c5d9d4b9fc7a7d0cb1ada4 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 25 Aug 2022 21:55:37 +0100 Subject: store laser and stars settings --- lasertext/src/lineTransformer.h | 1 - lasertext/src/ofApp.cpp | 43 ++++++++++++++++++++++++++++++++++++++--- lasertext/src/ofApp.h | 34 ++++++++++++++++++++++++-------- 3 files changed, 66 insertions(+), 12 deletions(-) diff --git a/lasertext/src/lineTransformer.h b/lasertext/src/lineTransformer.h index f5ec22f..9e44d1a 100644 --- a/lasertext/src/lineTransformer.h +++ b/lasertext/src/lineTransformer.h @@ -17,5 +17,4 @@ class lineTransformer { colourPolyline static polyLineTransform(ofPoint (*transferFunction)(const ofPoint),colourPolyline& poly,float colourFade=1.0f); ofPolyline static makePolygon(int num,float diam); void static drawPoly(ofPolyline poly,float x,float y); - }; \ No newline at end of file diff --git a/lasertext/src/ofApp.cpp b/lasertext/src/ofApp.cpp index a4e076d..89fa856 100644 --- a/lasertext/src/ofApp.cpp +++ b/lasertext/src/ofApp.cpp @@ -20,12 +20,14 @@ void ofApp::setup(){ banner.loadFont("fonts/EMSDecorousScript.svg"); // EMSPepita.svg"); //fonts.getPath(currentFont)); banner.init("Everything Is Going To Be Alright"); - starsgui.setup("stars","",5,350); + starsgui.setup("stars","",5,450); starsgui.add(stars_x.set("x", 0.0f, -2000.0f, 2000.0f)); starsgui.add(stars_y.set("y", 0.0f, -2000.0f, 2000.0f)); + starsgui.add(stars_rate.set("y", 1.0f, 0.01f, 3.0f)); starsgui.add(stars_radius.set("radius", 100.0f, 10.0f, 500.0f)); starsgui.add(stars_speed.set("speed", 5.0f, 0.0f, 10.0f)); starsgui.add(stars_life.set("life", 4.0f, 3.0f, 10.0f)); + starsgui.add(bScanStars.set("scan", true)); textgui.setup("text","",5,650); @@ -74,6 +76,19 @@ void ofApp::setup(){ laser_pos_y=XML.getValue("POSITION:Y", 0); laser_scale=XML.getValue("SCALE", 1.0f); + laser_intensity=XML.getValue("laser:intensity",30); + laser_points=XML.getValue("laser:points",30000); + laser_subdivide=XML.getValue("laser:subdivide",15); + laser_blank_num=XML.getValue("laser:blankpoints",8); + laser_max_angle=XML.getValue("laser:maxangle",15.0f); + + stars_x=XML.getValue("stars:X",0.0f); + stars_y=XML.getValue("stars:Y",0.0f); + stars_rate=XML.getValue("stars:rate",1.0f); + stars_radius=XML.getValue("stars:radius",100.0f); + stars_speed=XML.getValue("stars:speed",5.0f); + stars_life=XML.getValue("stars:life",4.0f); + stars.init(ofVec2f(2000.0f,2000.0f),100.0f,1.0,5.0,4.0,1.0); } @@ -104,6 +119,19 @@ void ofApp::save_settings(){ XML.setValue("SCALE", laser_scale); + XML.setValue("laser:intensity",laser_intensity); + XML.setValue("laser:points",laser_points); + XML.setValue("laser:subdivide",laser_subdivide); + XML.setValue("laser:blankpoints",laser_blank_num); + XML.setValue("laser:maxangle",laser_max_angle); + + XML.setValue("stars:X",stars_x); + XML.setValue("stars:Y",stars_y); + XML.setValue("stars:rate",stars_rate); + XML.setValue("stars:radius",stars_radius); + XML.setValue("stars:speed",stars_speed); + XML.setValue("stars:life",stars_life); + XML.saveFile("settings.xml"); cout << "settings.xml saved!" < starshapes=stars.getPoints(); + vector starshapes=stars.getPoints(); + + if (bScanStars){ + std::sort(starshapes.begin(),starshapes.end()); + } + + vector laserstars; + int numstars=0; for (auto& s: starshapes) { numstars+=s.size(); s.draw(); + laserstars.push_back((colourPolyline)s); } - num+=laser.draw(starshapes); + num+=laser.draw(laserstars); if (num>0){ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num)+", stars: "+ofToString(numstars)); diff --git a/lasertext/src/ofApp.h b/lasertext/src/ofApp.h index a78f0c2..a099cf6 100644 --- a/lasertext/src/ofApp.h +++ b/lasertext/src/ofApp.h @@ -9,6 +9,12 @@ #include "lineTransformer.h" #include "colourPolyline.h" +class scannableColourPolyline: public colourPolyline{ +public: + bool operator < (const scannableColourPolyline& line) const { + return (operator[](0).x < line[0].x); + } +}; class star{ public: @@ -68,10 +74,15 @@ public: float a=ofRandom(3.57f); float r=ofRandom(radius); ofVec2f offset=ofVec2f(cos(a)*r,sin(a)*r); + + //avoid having stars that don't move, for safety + a=ofRandom(3.57f); + r=(ofRandom(0.8)+0.2)*speed; + ofVec2f speed=ofVec2f(cos(a)*r,sin(a)*r); stars.push_back(star( offset, - ofVec2f(ofRandom(speed)-(speed/2),ofRandom(speed)-(speed/2)), + speed, lifespan+ofRandom(agevar)-(agevar/2) )); /* @@ -84,11 +95,11 @@ public: } } - vector getPoints(){ + vector getPoints(){ float now=ofGetElapsedTimef(); - vector o; + vector o; for(auto& s:stars){ - colourPolyline l; + scannableColourPolyline l; //ofLog()<<"get star"; l.addVertex(centre.x+s.pos.x,centre.y+s.pos.y,ofColor(1.0f-((now-s.birthday)/s.lifespan)*128.0f)); l.addVertex(centre.x+s.pos.x+1,centre.y+s.pos.y+1,ofColor(1.0f-((now-s.birthday)/s.lifespan)*128.0f)); @@ -240,6 +251,7 @@ public: } words.push_back(w); } + //ofLog()<<"created "< _words){ clear(); @@ -315,14 +327,18 @@ public: else { //proportional to #of letters int theletter=int(playhead)%glyphCount(); theword=0; - while((theletter-=words[theword].glyphs.size())>0){ + while(theletter>words[theword].glyphs.size()){ + theletter-=words[theword].glyphs.size(); theword++; } - segment=(((float)theletter+words[theword].glyphs.size()+playhead-int(playhead))/words[theword].glyphs.size()); - } + float playfraction=playhead-int(playhead); + + //segment=(((float)theletter+words[theword].glyphs.size()+playhead-int(playhead))/words[theword].glyphs.size()); + segment=(((float)theletter+playfraction-1)/words[theword].glyphs.size()); + } //calculate params for word/letter anim for (int i=0;i stars_x; ofParameter stars_y; + ofParameter stars_rate; ofParameter stars_radius; ofParameter stars_speed; ofParameter stars_life; + ofParameter bScanStars; ofxPanel textgui; ofParameter laser_scale; -- cgit v1.2.3