summaryrefslogtreecommitdiff
path: root/lasertext/src
diff options
context:
space:
mode:
authorTim Redfern <tim@getdrop.com>2022-08-14 23:18:51 +0100
committerTim Redfern <tim@getdrop.com>2022-08-14 23:18:51 +0100
commit895389c009da308c4a1f01d0f17d8304ea12c915 (patch)
tree3bb5b8e90a55bbce68e04b705dd019f37b324302 /lasertext/src
parent42f6a93907ccc11b1f8b4516d9c33524319a99cc (diff)
check in lasertest
Diffstat (limited to 'lasertext/src')
-rw-r--r--lasertext/src/main.cpp22
-rw-r--r--lasertext/src/ofApp.cpp135
-rw-r--r--lasertext/src/ofApp.h166
3 files changed, 323 insertions, 0 deletions
diff --git a/lasertext/src/main.cpp b/lasertext/src/main.cpp
new file mode 100644
index 0000000..3e20ab7
--- /dev/null
+++ b/lasertext/src/main.cpp
@@ -0,0 +1,22 @@
+#include "ofMain.h"
+#include "ofApp.h"
+
+
+//========================================================================
+int main(int argc, char *argv[]){
+
+
+ ofGLFWWindowSettings settings;
+
+ settings.setSize(1200,900);
+
+ //1200 = 13.2° = 42898 pts theoretical
+
+ shared_ptr<ofAppBaseWindow> mainWindow = ofCreateWindow(settings);
+
+ shared_ptr<ofApp> mainApp(new ofApp);
+
+ ofRunApp(mainWindow, mainApp);
+ ofRunMainLoop();
+}
+ \ No newline at end of file
diff --git a/lasertext/src/ofApp.cpp b/lasertext/src/ofApp.cpp
new file mode 100644
index 0000000..b6f4061
--- /dev/null
+++ b/lasertext/src/ofApp.cpp
@@ -0,0 +1,135 @@
+#include "ofApp.h"
+#include "glew.h"
+
+/*
+what do we want to store/control per letter?
+*/
+
+
+int MAX_POINTS=40000;
+int LASER_INTENSITY=128;
+
+//--------------------------------------------------------------
+void ofApp::setup(){
+ fonts.open("fonts/");
+ fonts.allowExt("svg");
+ fonts.listDir();
+ ofLogNotice()<<"found "<<fonts.size()<<" fonts";
+
+ currentFont=0;
+ 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);
+}
+//--------------------------------------------------------------
+void ofApp::update(){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::draw(){
+ ofBackground(0,0,0);
+ ofSetColor(255,255,255);
+
+ vector<colourPolyline> shapes = banner.getOutlines();
+
+ int num = laser.draw(shapes);
+
+ //banner.draw();
+
+ ofPushMatrix();
+ ofTranslate(ofGetWidth()/2,ofGetHeight()/2);
+ //ofScale(0.05,-0.05,0.05);
+ for (auto& s: shapes) s.draw();
+ ofPopMatrix();
+
+ if (num>0){
+ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser points: "+ofToString(num));
+ }
+ else {
+ ofSetWindowTitle(ofToString(ofGetFrameRate(), 2)+" fps laser error ");
+ }
+
+}
+
+
+//--------------------------------------------------------------
+void ofApp::exit() {
+
+}
+
+
+
+//--------------------------------------------------------------
+void ofApp::keyPressed(ofKeyEventArgs &args){
+
+
+
+}
+
+
+
+//--------------------------------------------------------------
+void ofApp::keyReleased(int key){
+ if (key>=' '&&key<='~'){
+ banner.addGlyph(key,ofColor::fromHsb(ofRandom(255.0),225,255));
+ }
+ else if (key==OF_KEY_BACKSPACE||key==OF_KEY_DEL) { //DEL
+ banner.removeGlyph();
+ }
+ ofLog()<<banner.length()<<" "<<key<<" "<<banner.text();
+
+ switch(key){
+ case OF_KEY_UP:{
+ currentFont=(currentFont+1)%fonts.size();
+ banner.loadFont(fonts.getPath(currentFont));
+ break;
+ }
+ case OF_KEY_DOWN:{
+ currentFont--;
+ if (currentFont<0) currentFont=fonts.size()-1;
+ banner.loadFont(fonts.getPath(currentFont));
+ break;
+ }
+ }
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseMoved(int x, int y ){
+
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseDragged(int x, int y, int button){
+}
+
+//--------------------------------------------------------------
+void ofApp::mousePressed(int x, int y, int button){
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseReleased(int x, int y, int button){
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseEntered(int x, int y){
+}
+
+//--------------------------------------------------------------
+void ofApp::mouseExited(int x, int y){
+}
+
+//--------------------------------------------------------------
+void ofApp::windowResized(int w, int h){
+}
+
+//--------------------------------------------------------------
+void ofApp::gotMessage(ofMessage msg){
+}
+
+//--------------------------------------------------------------
+void ofApp::dragEvent(ofDragInfo dragInfo){
+}
diff --git a/lasertext/src/ofApp.h b/lasertext/src/ofApp.h
new file mode 100644
index 0000000..e8c7da9
--- /dev/null
+++ b/lasertext/src/ofApp.h
@@ -0,0 +1,166 @@
+#pragma once
+
+#include "ofMain.h"
+#include "ofxSvg.h"
+
+#include "ofxHelios.h"
+#include "colourPolyline.h"
+
+class glyph{
+public:
+ glyph(char c,float w,vector<ofPolyline> lines){
+ glyph(c,w,lines,ofColor(0,0,0));
+ }
+ glyph(char c,float w,vector<ofPolyline> lines,ofColor col){
+ code=c;
+ width=w;
+ outline=lines;
+ colour=col;
+ }
+ void draw(float x, float y){
+ ofSetColor(colour);
+ ofPushMatrix();
+ ofTranslate(x,y);
+ for (auto& v:outline) v.draw();
+ ofPopMatrix();
+ }
+ char code;
+ float width;
+ vector<ofPolyline> outline;
+ ofColor colour;
+};
+
+class glyphbanner{
+ ofXml SVGFont;
+ vector<glyph> glyphs;
+ vector<colourPolyline> outlines;
+ ofVec2f centre;
+public:
+ glyphbanner(){};
+ void init(vector<string> message){
+ for (auto& word: message){
+ for (auto& c: word){
+ addGlyph(c,ofColor::fromHsb(ofRandom(255.0),225,255));
+ }
+ addGlyph(' ');
+ }
+ }
+ int length(){return glyphs.size();}
+ float width(){
+ float w=0.0f;
+ for (auto& i:glyphs) w+=i.width;
+ return w;
+ }
+ string text(){
+ string s;
+ for (auto& i:glyphs) s+=ofToString(i.code);
+ return s;
+ }
+ vector<ofColor> colours(){
+ vector<ofColor> c;
+ for (auto& i:glyphs) c.push_back(i.colour);
+ return c;
+ }
+ void loadFont(filesystem::path path){
+ if( SVGFont.load(path) ){
+ vector<glyph> g=glyphs;
+ clear();
+ createGlyphs(g);
+ ofLog()<<"loaded "<<path.stem().string();
+ }else{
+ ofLog()<<"unable to load "<<path<<" check data/ folder";
+ }
+
+ }
+ void createGlyphs(string text){
+ for (auto& c:text) addGlyph(c);
+ }
+ void createGlyphs(vector<glyph> _g){
+ for (auto& g:_g) addGlyph(g.code,g.colour);
+ }
+ void addGlyph(char c,ofColor col=ofColor(255,255,255)){
+ vector<ofPolyline> shapes;
+ ofPolyline shape;
+ string elementPath = "/svg/defs/font/glyph[@unicode='"+ofToString(c)+"']";
+
+ if(SVGFont.findFirst(elementPath) == 0 ){
+ elementPath = "/svg/defs/font/glyph[@unicode='?']";
+ }
+
+ ofXml xmlElement = SVGFont.findFirst(elementPath);
+
+ float charWidth = ofToFloat(xmlElement.getAttribute("horiz-adv-x").getValue());
+
+ vector<string> splitGlyphPath = ofSplitString(xmlElement.getAttribute("d").getValue(), " ");//glyph path data in SVG looks like this: "M 139 -9.45 L 230 18.9 L 299 22.1 L 227 25.2"
+
+ for(int i=0; i<splitGlyphPath.size(); i+=3){
+ if(splitGlyphPath[i] == "M"){
+ if (shape.size()) {
+ shapes.push_back(shape);
+ shape.clear();
+ }
+ shape.addVertex(ofToFloat(splitGlyphPath[i+1]), ofToFloat(splitGlyphPath[i+2]));
+ }else if(splitGlyphPath[i] == "L"){
+ shape.lineTo(ofToFloat(splitGlyphPath[i+1]), ofToFloat(splitGlyphPath[i+2]));
+ }
+ }
+ if (shape.size()) shapes.push_back(shape);
+ glyphs.push_back(glyph(c,charWidth,shapes,col));
+ }
+ void removeGlyph(){glyphs.pop_back();}
+ void clear(){glyphs.clear();}
+ void randomiseColours();
+ void draw(){
+ float p=(-width())/2;
+ ofPushMatrix();
+ ofTranslate(ofGetWidth()/2,ofGetHeight()/2);
+ ofScale(0.05,-0.05,0.05);
+ for (auto& i:glyphs){
+ i.draw(p,0);
+ p+=i.width;
+ }
+ ofPopMatrix();
+ }
+ vector<colourPolyline>& getOutlines(){
+ outlines.clear();
+ float p=(-width())/2;
+ for (auto& i:glyphs){
+ for (auto& o:i.outline){
+ auto q=o;
+ q.scale(.05,-.05);
+ q.translate(glm::vec3(p*.05,0,0));
+ outlines.push_back(colourPolyline(q,i.colour));
+ }
+ p+=i.width;
+ }
+ return outlines;
+ }
+};
+
+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);
+
+ ofxHelios laser;
+
+ ofDirectory fonts;
+ int currentFont;
+ string displaytext;
+ glyphbanner banner;
+
+};