diff options
| author | Tim Redfern <tim@getdrop.com> | 2022-08-19 13:33:06 +0100 |
|---|---|---|
| committer | Tim Redfern <tim@getdrop.com> | 2022-08-19 13:33:06 +0100 |
| commit | 77ce73a9b57cf3deac08720b449886b71412ea2f (patch) | |
| tree | b0a388e36993132f8b2d3bbca02504d90ca07b30 /lasertext/src/ofApp.h | |
| parent | 08968b9557456b3b9d3566d4dca1b9190bd8fba1 (diff) | |
text with mapping and moveable star emitter
Diffstat (limited to 'lasertext/src/ofApp.h')
| -rw-r--r-- | lasertext/src/ofApp.h | 128 |
1 files changed, 120 insertions, 8 deletions
diff --git a/lasertext/src/ofApp.h b/lasertext/src/ofApp.h index d87f37f..a78f0c2 100644 --- a/lasertext/src/ofApp.h +++ b/lasertext/src/ofApp.h @@ -6,9 +6,97 @@ #include "ofxXmlSettings.h" #include "ofxHelios.h" +#include "lineTransformer.h" #include "colourPolyline.h" +class star{ +public: + star(ofVec2f p,ofVec2f v,float l){ + pos=p; + vel=v; + birthday=ofGetElapsedTimef(); + lifespan=l; + } + void update(vector<star>& stars){ + pos+=vel; + } + ofVec2f pos; + ofVec2f vel; + float birthday; + float lifespan; +}; + +class starSystem{ +public: + vector<star> 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); + } + void init(ofVec2f c, float _rad,float r,float s,float l,float v){ + centre=c; + radius=_rad; + rate=r; + speed=s; + lifespan=l; + agevar=v; + } + void update(){ + float now=ofGetElapsedTimef(); + float segment=now-last; + last=now; + for(auto it = stars.begin(); it != stars.end();) + { + if(now-it->birthday>it->lifespan){ + //ofLog()<<"erase star"; + it = stars.erase(it); + } + else { + //ofLog()<<"update star"; + it->update(stars); + ++it; + } + } + if (ofRandom(rate)<segment){ + float a=ofRandom(3.57f); + float r=ofRandom(radius); + ofVec2f offset=ofVec2f(cos(a)*r,sin(a)*r); + + stars.push_back(star( + offset, + ofVec2f(ofRandom(speed)-(speed/2),ofRandom(speed)-(speed/2)), + lifespan+ofRandom(agevar)-(agevar/2) + )); + /* + ofLog()<<"create star: "<< + ofVec2f(ofRandom(ofGetWidth()),ofRandom(ofGetHeight()))<<", "<< + ofVec2f(ofRandom(speed)-(speed/2),ofRandom(speed)-(speed/2))<<" lifespan: "<< + lifespan+ofRandom(agevar)-(agevar/2); + */ + + + } + } + vector<colourPolyline> getPoints(){ + float now=ofGetElapsedTimef(); + vector<colourPolyline> o; + for(auto& s:stars){ + colourPolyline 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); + } + return o; + } +}; class glyph{ public: @@ -137,7 +225,7 @@ public: } } - void createWords(string message,bool usePalette=true){ + void createWords(string message,bool usePalette=false){ clear(); vector<string> m=split(message); for (auto& word: m){ @@ -146,7 +234,8 @@ public: w.glyphs.push_back(getGlyph(c, usePalette? palette[ofRandom(palette.size())]: - ofColor::fromHsb(ofRandom(255.0),225,255) + //112->231 hue sat 0->255 brightness 255 + ofColor::fromHsb(ofRandom(119)+112,ofRandom(255),255) )); } words.push_back(w); @@ -191,13 +280,13 @@ public: if (shape.size()) shapes.push_back(shape); return glyph(c,charWidth,shapes,col); } - void addGlyph(char g,bool usePalette=true){ + void addGlyph(char g,bool usePalette=false){ if (g==' ') words.push_back(glyphWord()); else { words[words.size()-1].glyphs.push_back(getGlyph(g, usePalette? palette[ofRandom(palette.size())]: - ofColor::fromHsb(ofRandom(255.0),225,255) + ofColor::fromHsb(ofRandom(119)+112,ofRandom(255),255) )); } } @@ -211,7 +300,7 @@ public: } } void clear(){words.clear();} - void update(float speed=1.0f,float usePalette=true){ + void update(float speed=1.0f,float usePalette=false){ float delta=ofGetElapsedTimef()-lastUpdateTime; lastUpdateTime=ofGetElapsedTimef(); @@ -239,7 +328,7 @@ public: g.colour= usePalette? palette[ofRandom(palette.size())]: - ofColor::fromHsb(ofRandom(255.0),225,255); + ofColor::fromHsb(ofRandom(119)+112,ofRandom(255),255); } } } @@ -255,7 +344,7 @@ public: for (auto& o:g.outline){ auto q=o; q.scale(s,-s); - q.translate(glm::vec3(p*s,0,0)); + q.translate(glm::vec3(p*s,-ofGetHeight()/3,0)); outlines.push_back(colourPolyline(q,g.colour*w.amount)); } } @@ -286,6 +375,9 @@ class ofApp : public ofBaseApp{ void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); + void default_settings(); + void save_settings(); + ofxHelios laser; ofDirectory fonts; @@ -293,8 +385,17 @@ class ofApp : public ofBaseApp{ string displaytext; glyphbanner banner; + ofxPanel starsgui; + ofParameter<float> stars_x; + ofParameter<float> stars_y; + ofParameter<float> stars_radius; + ofParameter<float> stars_speed; + ofParameter<float> stars_life; + ofxPanel textgui; - ofParameter<float> text_scale; + ofParameter<float> laser_scale; + ofParameter<float> laser_pos_x; + ofParameter<float> laser_pos_y; ofParameter<float> text_speed; //======= laser gui @@ -309,4 +410,15 @@ class ofApp : public ofBaseApp{ ofxXmlSettings XML; + starSystem stars; + + glm::vec2 warpframe[4]; + int select_warpframe; + bool bDrawFrame; + + ofPoint outputWindowSize; + + ofPoint outputPosition; + float outputScale; + }; |
