#pragma once #include "ofMain.h" #include "ofxSvg.h" #include "ofxGui.h" #include "ofxXmlSettings.h" #include "ofxHelios.h" #include "lineTransformer.h" #include "colourPolyline.h" #include "vectortext.h" class scannableColourPolyline: public colourPolyline{ public: bool operator < (const scannableColourPolyline& line) const { return (operator[](0).x < line[0].x); } }; class star{ public: star(ofVec2f p,ofVec2f v,float l){ pos=p; vel=v; birthday=ofGetElapsedTimef(); lifespan=l; } void update(vector& stars){ pos+=vel; } ofVec2f pos; ofVec2f vel; float birthday; float lifespan; }; class starSystem{ public: vector stars; float agevar; float last; ofxPanel gui; ofParameter x; ofParameter y; ofParameter rate; ofParameter radius; ofParameter speed; ofParameter lifespan; ofParameter bScan; starSystem(){ } 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(); 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) getPoints(){ float now=ofGetElapsedTimef(); vector s; for(auto& star:stars){ scannableColourPolyline l; //ofLog()<<"get star"; 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()); } vector o; int numstars=0; for (auto& shape: s) { shape.draw(); o.push_back((colourPolyline)shape); } return o; } }; class ofApp : public ofBaseApp{ public: void setup(); void update(); void draw(); void exit(); void keyPressed(ofKeyEventArgs &keyargs); void keyReleased(int key); void mouseMoved(int x, int y ); void mouseDragged(int x, int y, int button); void mousePressed(int x, int y, int button); void mouseReleased(int x, int y, int button); void mouseEntered(int x, int y); void mouseExited(int x, int y); void windowResized(int w, int h); void dragEvent(ofDragInfo dragInfo); void gotMessage(ofMessage msg); void default_settings(); void save_settings(); ofxHelios laser; ofDirectory fonts; int currentFont; string displaytext; glyphbanner banner; ofxPanel textgui; ofParameter laser_scale; ofParameter laser_pos_x; ofParameter laser_pos_y; ofParameter text_speed; //======= laser gui ofxPanel lasergui; ofParameter laser_power; ofParameter laser_intensity; ofParameter laser_points; ofParameter laser_subdivide; ofParameter laser_blank_num; ofParameter laser_max_angle; ofxXmlSettings XML; starSystem stars; glm::vec2 warpframe[4]; int select_warpframe; bool bDrawFrame; ofPoint outputWindowSize; ofPoint outputPosition; float outputScale; };