From 6c6bb89f8b3bd00fa7fc693e8dedc65efd502c0b Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Thu, 17 Aug 2023 22:41:00 +0100 Subject: object oriented stars+gui --- lasertext/src/ofApp.cpp | 69 +++++++++++++++++-------------------------------- lasertext/src/ofApp.h | 69 ++++++++++++++++++++++++++++--------------------- 2 files changed, 63 insertions(+), 75 deletions(-) (limited to 'lasertext/src') diff --git a/lasertext/src/ofApp.cpp b/lasertext/src/ofApp.cpp index b5fb1ae..e7341fa 100644 --- a/lasertext/src/ofApp.cpp +++ b/lasertext/src/ofApp.cpp @@ -3,6 +3,11 @@ /* what do we want to store/control per letter? + + +1. play back arbitrary text +2. web server to submit text +3. animate based on audio */ @@ -20,15 +25,7 @@ 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,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)); - + stars.init("stars",5,450); textgui.setup("text","",5,650); textgui.add(laser_scale.set("scale", 1.0f, 0.5f, 3.0f)); @@ -82,14 +79,14 @@ void ofApp::setup(){ 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.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.lifespan=XML.getValue("stars:life",4.0f); - stars.init(ofVec2f(2000.0f,2000.0f),100.0f,1.0,5.0,4.0,1.0); + //stars.init(ofVec2f(2000.0f,2000.0f),100.0f,1.0,5.0,4.0,1.0); } @@ -125,12 +122,12 @@ void ofApp::save_settings(){ 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.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.lifespan); XML.saveFile("settings.xml"); cout << "settings.xml saved!" < 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); - } + vector laserstars=stars.getPoints(); num+=laser.draw(laserstars); if (num>0){ - ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num)+", stars: "+ofToString(numstars)); + ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num)+", stars: "+ofToString(laserstars.size())); } else { - ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser power off, stars: "+ofToString(numstars)); + ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser power off, stars: "+ofToString(laserstars.size())); } diff --git a/lasertext/src/ofApp.h b/lasertext/src/ofApp.h index 621b729..052d565 100644 --- a/lasertext/src/ofApp.h +++ b/lasertext/src/ofApp.h @@ -37,23 +37,30 @@ public: class starSystem{ public: vector stars; - ofVec2f centre; - float radius; - float rate; - float speed; - float lifespan; float agevar; float last; - starSystem(ofVec2f c=ofVec2f(0,0), float _rad=100,float r=0.5,float s=5.0,float l=5.0,float v=1.0){ - init(c,_rad,r,s,l,v); + ofxPanel gui; + ofParameter x; + ofParameter y; + ofParameter rate; + ofParameter radius; + ofParameter speed; + ofParameter lifespan; + ofParameter bScan; + starSystem(){ } - void init(ofVec2f c, float _rad,float r,float s,float l,float v){ - centre=c; - radius=_rad; - rate=r; - speed=s; - lifespan=l; + void init(string name="",int _gx=5, int _gy=5, float _x=0, float _y=0, float _rad=100,float r=0.5,float s=5.0,float l=5.0,float v=1.0){ + agevar=v; + + gui.setup(name,"",_gx,_gy); + gui.add(x.set("x", _x, -2000.0f, 2000.0f)); + gui.add(y.set("y", _y, -2000.0f, 2000.0f)); + gui.add(rate.set("rate", r, 0.01f, 3.0f)); + gui.add(radius.set("radius", _rad, 10.0f, 500.0f)); + gui.add(speed.set("speed", s, 0.0f, 10.0f)); + gui.add(lifespan.set("life", l, 3.0f, 10.0f)); + gui.add(bScan.set("scan", true)); } void update(){ float now=ofGetElapsedTimef(); @@ -96,17 +103,30 @@ public: } } - vector getPoints(){ + vector getPoints(){ float now=ofGetElapsedTimef(); - vector o; - for(auto& s:stars){ + vector s; + for(auto& star:stars){ 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)); - o.push_back(l); + l.addVertex(x+star.pos.x,y+star.pos.y,ofColor(1.0f-((now-star.birthday)/star.lifespan)*128.0f)); + l.addVertex(x+star.pos.x+1,y+star.pos.y+1,ofColor(1.0f-((now-star.birthday)/star.lifespan)*128.0f)); + s.push_back(l); + } + + if (bScan){ + std::sort(s.begin(),s.end()); } - return o; + + vector o; + + int numstars=0; + for (auto& shape: s) { + shape.draw(); + o.push_back((colourPolyline)shape); + } + + return o; } }; @@ -141,15 +161,6 @@ class ofApp : public ofBaseApp{ string displaytext; glyphbanner banner; - ofxPanel starsgui; - ofParameter stars_x; - ofParameter stars_y; - ofParameter stars_rate; - ofParameter stars_radius; - ofParameter stars_speed; - ofParameter stars_life; - ofParameter bScanStars; - ofxPanel textgui; ofParameter laser_scale; ofParameter laser_pos_x; -- cgit v1.2.3