From 1fe5dceef2df8cb7a67e0760507be418bee754b8 Mon Sep 17 00:00:00 2001 From: Tim Redfern Date: Tue, 16 Aug 2022 16:44:55 +0100 Subject: animate with timing --- lasertext/src/ofApp.cpp | 16 +++++++--------- lasertext/src/ofApp.h | 24 +++++++++++++++++------- 2 files changed, 24 insertions(+), 16 deletions(-) (limited to 'lasertext/src') diff --git a/lasertext/src/ofApp.cpp b/lasertext/src/ofApp.cpp index 2974056..96b56ab 100644 --- a/lasertext/src/ofApp.cpp +++ b/lasertext/src/ofApp.cpp @@ -5,10 +5,6 @@ what do we want to store/control per letter? */ - -int MAX_POINTS=40000; -int LASER_INTENSITY=128; - //-------------------------------------------------------------- void ofApp::setup(){ fonts.open("fonts/"); @@ -20,10 +16,11 @@ void ofApp::setup(){ banner.loadFont("fonts/EMSPepita.svg"); //fonts.getPath(currentFont)); banner.init("Everything Is Going To Be Alright"); - laser.set_pts(MAX_POINTS); - laser.set_intensity(LASER_INTENSITY); + textgui.setup("text","",5,680); + textgui.add(text_scale.set("scale", 1.0f, 0.5f, 3.0f)); + textgui.add(text_speed.set("speed", 1.0f, 0.0f, 2.0f)); - lasergui.setup("laser","",5,700); + lasergui.setup("laser","",5,750); lasergui.add(laser_power.set("power", true)); lasergui.add(laser_intensity.set("intensity", 30, 0, 255)); lasergui.add(laser_points.set("points", 30000, 0, 40000)); @@ -41,7 +38,7 @@ void ofApp::setup(){ } //-------------------------------------------------------------- void ofApp::update(){ - banner.update(1.0f); + banner.update(text_speed); laser.set_pts(laser_points); laser.set_subdivide(laser_subdivide); @@ -56,9 +53,10 @@ void ofApp::draw(){ ofBackground(0,0,0); ofSetColor(255,255,255); + textgui.draw(); lasergui.draw(); - vector shapes = banner.getOutlines(0.08f); //+(0.02f*sin(ofGetElapsedTimef()*.1f))); + vector shapes = banner.getOutlines(0.08f*text_scale); //+(0.02f*sin(ofGetElapsedTimef()*.1f))); int num = 0; diff --git a/lasertext/src/ofApp.h b/lasertext/src/ofApp.h index 3fcde84..5ca1895 100644 --- a/lasertext/src/ofApp.h +++ b/lasertext/src/ofApp.h @@ -50,6 +50,7 @@ class glyphbanner{ vector outlines; ofVec2f centre; float lastUpdateTime; + float playhead; float enspace; vector split(string s) { size_t pos_start = 0, pos_end; @@ -70,6 +71,7 @@ public: void init(string message){ createWords(message); lastUpdateTime=ofGetElapsedTimef(); + playhead=0.0f; } int length(){ int l=0; @@ -177,27 +179,31 @@ public: } } void clear(){words.clear();} - void update(float period=1.0f){ - float t=ofGetElapsedTimef()/period; + void update(float speed=1.0f){ + + float delta=ofGetElapsedTimef()-lastUpdateTime; + lastUpdateTime=ofGetElapsedTimef(); + playhead+=delta*speed; + int theword=0; float segment=0.0f; if (false){ //1 word per second - theword=int(t)%words.size(); - segment=t-int(t); + theword=int(playhead)%words.size(); + segment=playhead-int(playhead); } else { //proportional to #of letters - int theletter=int(t)%glyphCount(); + int theletter=int(playhead)%glyphCount(); theword=0; while((theletter-=words[theword].glyphs.size())>0){ theword++; } - segment=(((float)theletter+words[theword].glyphs.size()+t-int(t))/words[theword].glyphs.size()); + segment=(((float)theletter+words[theword].glyphs.size()+playhead-int(playhead))/words[theword].glyphs.size()); } //calculate params for word/letter anim for (int i=0;i text_scale; + ofParameter text_speed; + //======= laser gui ofxPanel lasergui; -- cgit v1.2.3