summaryrefslogtreecommitdiff
path: root/nextus/src
diff options
context:
space:
mode:
Diffstat (limited to 'nextus/src')
-rw-r--r--nextus/src/lineClipper.cpp56
-rw-r--r--nextus/src/lineClipper.h9
-rw-r--r--nextus/src/main.cpp2
-rw-r--r--nextus/src/ofApp.cpp26
-rw-r--r--nextus/src/ofApp.h18
-rw-r--r--nextus/src/vectorPlugin.cpp19
-rw-r--r--nextus/src/vectorPlugin.h97
-rw-r--r--nextus/src/vectorText.h43
8 files changed, 183 insertions, 87 deletions
diff --git a/nextus/src/lineClipper.cpp b/nextus/src/lineClipper.cpp
index eb9c480..135e840 100644
--- a/nextus/src/lineClipper.cpp
+++ b/nextus/src/lineClipper.cpp
@@ -1,36 +1,50 @@
#include "lineClipper.h"
-vector <colourPolyline> lineClipper::mask(
+/*
+PONK coords are normalised -1<x<1
+this scales everything by 10^4 to allow integer math to work
+on shapes at screen res
+*/
+
+#define SCALE_FROM_OF 10000
+#define SCALE_TO_OF 0.0001
+
+vector <colourPolyline> lineClipper::clip(
vector <colourPolyline> shapes,
- ofRectangle frame,
+ ofPolyline mask,
bool invert
)
{
+ //this supports one colour per polyline
vector <colourPolyline> output;
- ofx::Clipper clipper;
-
- clipper.Clear();
- clipper.addRectangle(frame, ClipperLib::ptClip, true);
- vector <ofPolyline> polys; //TODO make clipper clip colourpolylines
+ if (shapes.size()){
- for (auto& shape: shapes) polys.push_back(shape);
-
- clipper.addPolylines(polys,ClipperLib::ptSubject);
+ ofx::Clipper clipper;
- vector <ofPolyline> clipped;
+ mask.scale(SCALE_FROM_OF,SCALE_FROM_OF);
- if (invert){
- clipped = clipper.getClipped(ClipperLib::ctDifference);
- }else {
- clipped = clipper.getClipped(ClipperLib::ctIntersection);
- }
+ for (auto& shape: shapes) {
- for (auto& clip: clipped)
- {
- //clip.simplify(contour_simplify);
- output.push_back(colourPolyline(clip,shapes[0].getColourAt(0)));
- }
+ clipper.Clear();
+ clipper.addPolyline(mask, ClipperLib::ptClip);
+ shape.scale(SCALE_FROM_OF,SCALE_FROM_OF);
+ clipper.addPolyline(shape,ClipperLib::ptSubject);
+ vector <ofPolyline> clipped;
+ if (invert){
+ clipped = clipper.getClippedLines(ClipperLib::ctDifference);
+ }else {
+ clipped = clipper.getClippedLines(ClipperLib::ctIntersection);
+ }
+
+ for (auto& clip: clipped)
+ {
+ //clip.simplify(contour_simplify);
+ clip.scale(SCALE_TO_OF,SCALE_TO_OF);
+ output.push_back(colourPolyline(clip,shape.getColourAt(0)));
+ }
+ }
+ }
return output;
} \ No newline at end of file
diff --git a/nextus/src/lineClipper.h b/nextus/src/lineClipper.h
index 7b098a1..209f30f 100644
--- a/nextus/src/lineClipper.h
+++ b/nextus/src/lineClipper.h
@@ -5,14 +5,19 @@
#include "colourPolyline.h"
+/*
+https://github.com/roymacdonald/ofxClipper
+this for of ofClipper supports clipping open lines
+*/
+
class lineClipper {
public:
lineClipper(){
}
- vector <colourPolyline> static mask(
+ vector <colourPolyline> static clip(
vector <colourPolyline> shapes,
- ofRectangle frame,
+ ofPolyline mask,
bool invert=false);
};
diff --git a/nextus/src/main.cpp b/nextus/src/main.cpp
index 3eb78b7..7e4ac16 100644
--- a/nextus/src/main.cpp
+++ b/nextus/src/main.cpp
@@ -10,7 +10,7 @@ int main(int argc, char *argv[]){
settings.decorated = true;
- settings.setSize(1200,700);
+ settings.setSize(1330,700);
settings.setPosition(ofVec2f(0,0));
settings.resizable = false;
diff --git a/nextus/src/ofApp.cpp b/nextus/src/ofApp.cpp
index 22e3d11..1964792 100644
--- a/nextus/src/ofApp.cpp
+++ b/nextus/src/ofApp.cpp
@@ -15,7 +15,7 @@ void ofApp::setup(){
load_settings();
- madlaser.setup("madlaser",995,510);
+ madlaser.setup("madlaser",1125,510);
ofSetFrameRate(60);
}
@@ -65,14 +65,27 @@ void ofApp::draw(){
networkinput.draw();
svginput.draw();
textinput.draw();
+ switcher.draw();
//process the pipeline
- vector<colourPolyline> output=textinput.clipOutput();
+ vector<colourPolyline> output;
+ if (switcher.network){
+ vector<colourPolyline> networkoutput=networkinput.clipOutput();
+ output.insert(end(output), begin(networkoutput), end(networkoutput));
+ }
+ if (switcher.svg){
+ vector<colourPolyline> svgoutput=svginput.clipOutput();
+ output.insert(end(output), begin(svgoutput), end(svgoutput));
+ }
+ if (switcher.text){
+ vector<colourPolyline> textoutput=textinput.clipOutput();
+ output.insert(end(output), begin(textoutput), end(textoutput));
+ }
int points=0;
ofPushMatrix();
- ofTranslate(695,5);
+ ofTranslate(825,5);
ofSetColor(255);
ofNoFill();
ofDrawRectangle(0,0,500,500);
@@ -178,11 +191,12 @@ void ofApp::dragEvent(ofDragInfo dragInfo){
string filename= *dragInfo.files.begin();
string extension= filename.substr(filename.find_last_of(".") + 1);
if (extension == "svg") {
- if (filename.find_last_of("fonts")){
- textinput.loadFont(filename);
+ if (string::npos==filename.find("fonts")){
+ svginput.load(filename);
}
else {
- svginput.load(filename);
+ ofLog()<<"found a font";
+ textinput.loadFont(filename);
}
} else if (extension == "txt"){
textinput.loadText(filename);
diff --git a/nextus/src/ofApp.h b/nextus/src/ofApp.h
index e2c90dd..e2aedb0 100644
--- a/nextus/src/ofApp.h
+++ b/nextus/src/ofApp.h
@@ -14,6 +14,19 @@
#include "lineSegmenter.h"
#include "vectorPlugin.h"
+class switcherPanel: public ofxPanel{
+ public:
+ switcherPanel(int x,int y){
+ setup("switcher","",x,y);
+ add(network.set("network",false));
+ add(svg.set("svg",true));
+ add(text.set("text",false));
+ }
+ ofParameter<bool> network;
+ ofParameter<bool> svg;
+ ofParameter<bool> text;
+};
+
class ofApp: public ofBaseApp, public ofxMidiListener {
public:
@@ -21,7 +34,8 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
ofApp() :
networkinput("network",DISPLAYSIZE,ofPoint(5,5)),
svginput("svg",DISPLAYSIZE,ofPoint(210,5)),
- textinput("text",DISPLAYSIZE,ofPoint(415,5)) {}
+ textinput("text",DISPLAYSIZE,ofPoint(415,5)),
+ switcher(620,5) {}
void setup();
void update();
@@ -62,6 +76,8 @@ class ofApp: public ofBaseApp, public ofxMidiListener {
//======================================= //output
+ switcherPanel switcher;
+
ofxPONKSenderPanel madlaser;
};
diff --git a/nextus/src/vectorPlugin.cpp b/nextus/src/vectorPlugin.cpp
index c87de08..8a5a53d 100644
--- a/nextus/src/vectorPlugin.cpp
+++ b/nextus/src/vectorPlugin.cpp
@@ -44,13 +44,14 @@ void svgPanel::load(string filename){
ofColor c1=path.getStrokeColor();
ofColor colour=path.getFillColor();
if (colour.r==colour.g&&colour.g==colour.b){
+ //if there appears to be no fill colour resort to stroke
colour=c1;
- }
+ };
segmenters.push_back(
colourLineSegmenter(
xformed,
- path.getStrokeColor()
+ colour
)
);
shape_selection_durations.push_back(0.0f);
@@ -180,17 +181,15 @@ vector<colourPolyline> svgPanel::getLines(){
}
}
}
- /*
- this should happen at output stage?
- if (contour_useColour){
- vector<colourPolyline> newPolys;
- for (auto p: output){
- newPolys.push_back(colourPolyline((ofPolyline)p,ofColor(laser_R,laser_G,laser_B))) ;
+ //this should happen at output stage?
+
+ if (colourise){
+ for (auto p=output.begin();p!=output.end();p++){
+ p->setColour(ofColor(255,255,255));
}
- output=newPolys;
}
- */
+
//}
return output;
} \ No newline at end of file
diff --git a/nextus/src/vectorPlugin.h b/nextus/src/vectorPlugin.h
index 78ce06d..a2cdb84 100644
--- a/nextus/src/vectorPlugin.h
+++ b/nextus/src/vectorPlugin.h
@@ -23,28 +23,16 @@ class vectorPanel {
position=_pos;
panel.setup(_title,"",_pos.x,_pos.y+size.y+5);
- /*
+
float f1=-1.0;
float f2=1.0;
- vector<glm::vec3> v1 = {{f1,f1,0},{f2,f1,0}};
- vector<glm::vec3> v2 = {{f2,f1,0},{f2,f2,0}};
- vector<glm::vec3> v3 = {{f2,f2,0},{f1,f2,0}};
- vector<glm::vec3> v4 = {{f1,f2,0},{f1,f1,0}};
- ofPolyline p1,p2,p3,p4;
- p1.addVertices(v1);
- p2.addVertices(v2);
- p3.addVertices(v3);
- p4.addVertices(v4);
- frame.push_back(p1);
- frame.push_back(p2);
- frame.push_back(p3);
- frame.push_back(p4);
- */
- ofPolyline p=ofPolyline().fromRectangle(ofRectangle(-1.0f,-1.0f,2.0f,2.0f));
- p.close();
-
- frame.push_back(p);
+ frame.addVertex(f1,f1);
+ frame.addVertex(f2,f1);
+ frame.addVertex(f2,f2);
+ frame.addVertex(f1,f2);
+ frame.close();
+
}
void draw(){
panel.draw();
@@ -64,18 +52,19 @@ class vectorPanel {
ofPopMatrix();
}
vector<colourPolyline> clipOutput() {
- ofLog()<<"frame has "<<frame.size()<<" paths";
- return lineClipper::mask(getOutput(),ofRectangle(-1.0f,-1.0f,2.0f,2.0f));
+ //ofLog()<<"frame has "<<frame.size()<<" paths";
+ return lineClipper::clip(getOutput(),frame);
};
- vector<colourPolyline> getOutput() {return getLines();};
- virtual vector<colourPolyline> getLines() {};
- virtual void update() {};
+ virtual vector<colourPolyline> getOutput()=0;
+ //vector<colourPolyline> getOutput(){return getLines();}
+ virtual vector<colourPolyline> getLines()=0;
+ virtual void update()=0;
protected:
ofVec2f size;
ofPoint position;
ofxPanel panel;
- vector <ofPolyline> frame;
+ ofPolyline frame;
};
class defaultPanel: public vectorPanel{
@@ -86,6 +75,9 @@ class defaultPanel: public vectorPanel{
ofVec2f _size=DISPLAYSIZE,
ofVec2f _pos=ofPoint(5,5)
) : vectorPanel(_title,_size,_pos){}
+ vector<colourPolyline> getOutput(){
+ return getLines();
+ }
vector<colourPolyline> getLines(){
vector<colourPolyline> output;
return output;
@@ -103,22 +95,39 @@ class transformPanel: public vectorPanel{
) : vectorPanel(_title,_size,_pos){
origin=ofPoint(0,0);
rotation=0;
- panel.add(use_rotate.set("rotate",false));
+ scale_time=0;
+ panel.add(transform.set("transform",false));
+ panel.add(use_rotate.set("rotate enable",false));
panel.add(rotation_delta.set("rotation",0.1,-2.0,2.0));
+ panel.add(use_scale.set("scale enable",false));
+ panel.add(scale_factor.set("scale factor",0.1,0.0,10.0));
+ panel.add(scale_osc_freq.set("scale osc freq",0.1,0.01,2.0));
+ panel.add(scale_osc_scale.set("scale osc scale",0.0,0.0,10.0));
+ panel.add(randomise.setup("randomise"));
+ randomise.addListener(this,&transformPanel::randomiseScale);
+ }
+ void randomiseScale(){
+ scale_time=ofRandom(6.3f);
}
void update(){
timedelta=ofGetElapsedTimef()-last_frame_time;
last_frame_time=ofGetElapsedTimef();
if (use_rotate) rotation+=rotation_delta*timedelta;
+ if (use_scale) {
+ scale_time+=timedelta*scale_osc_freq;
+ scale=scale_factor+((sin(scale_time)+1.0)*scale_osc_scale);
+ }
};
vector<colourPolyline> getOutput(){
vector<colourPolyline> lines=getLines();
- if (use_rotate){
+ if (transform){
ofMatrix4x4 rm = ofMatrix4x4::newIdentityMatrix();
rm.rotateRad(rotation,0,0,1);
- //if (use_scale){
- // rm.scale(scale_amt,scale_amt,scale_amt);
+ if(use_scale){
+ rm.scale(scale,scale,scale);
+ }
+
//}
//rm.translate(outputWindowSize.x/2,outputWindowSize.y/2,0);
vector<colourPolyline> transformedLines;
@@ -132,8 +141,16 @@ class transformPanel: public vectorPanel{
protected:
ofPoint origin;
float rotation;
+ float scale;
+ float scale_time;
+ ofParameter<bool> transform;
ofParameter<bool> use_rotate;
ofParameter<float> rotation_delta;
+ ofParameter<bool> use_scale;
+ ofParameter<float> scale_factor;
+ ofParameter<float> scale_osc_freq;
+ ofParameter<float> scale_osc_scale;
+ ofxButton randomise;
float last_frame_time, timedelta;
};
@@ -152,6 +169,7 @@ class svgPanel: public transformPanel{
ofVec2f _pos=ofPoint(5,5)
) : transformPanel(_title,_size,_pos){
panel.add(shapeslabel.setup("SHAPES",""));
+ panel.add(colourise.set("colourise",false));
panel.add(shapes_randomise.set("randomise",false));
//panel.add(shapes_generate.setup("generate"));
panel.add(shapes_amount.set("amount",0.2,0.0,1.0));
@@ -179,7 +197,7 @@ class svgPanel: public transformPanel{
//ofxFloatSlider contour_simplify;
ofxLabel shapeslabel;
- //svg gui
+ ofParameter<bool> colourise;
ofParameter<bool> shapes_randomise;
ofxButton shapes_generate;
ofParameter<float> shapes_amount;
@@ -207,31 +225,37 @@ class svgPanel: public transformPanel{
};
-class textPanel: public vectorPanel{
+class textPanel: public transformPanel{
public:
textPanel(
string _title="",
ofVec2f _size=DISPLAYSIZE,
ofVec2f _pos=ofPoint(5,5)
- ) : vectorPanel(_title,_size,_pos){
+ ) : transformPanel(_title,_size,_pos){
+ styles={"Style: Words","Style: Overlapping","Style: Sentence"};
panel.add(use_beat.set("use beat", false));
panel.add(beat_duration.set("duration factor", 0.5f, 0.0f, 1.0f));
- panel.add(text_speed.set("speed", 5.0f, 0.0f, 25.0f));
+ panel.add(text_speed.set("speed", 5.0f, 0.0f, 100.0f));
panel.add(text_scale.set("scale", 0.001f, 0.0f, 0.01f));
panel.add(enable_anim.set("animate", true));
- panel.add(spread_anim.set("spread", true));
+ panel.add(anim_style.set(styles[0], 0,0,styles.size()-1));
panel.add(anim_rev.set("reverse", false));
panel.add(vert_pos.set("vert_pos", 0.0f, -0.3f, 0.3f));
panel.add(vert_spread.set("vert_spread", 0.0f, -0.3f, 0.3f));
text.loadFont("fonts/EMSOsmotron.svg");
+ anim_style.addListener(this,&textPanel::styleChanged);
}
void update(){
+ transformPanel::update();
text.update();
}
+ void styleChanged(int &style){
+ anim_style.setName(styles[style]);
+ }
vector<colourPolyline> getLines(){
vector<colourPolyline> shapes=text.getOutlines(
text_scale,
- spread_anim?STYLE_OVERLAPPING:STYLE_SENTENCE,
+ anim_style,
0,0,
enable_anim,
anim_rev,
@@ -257,11 +281,12 @@ class textPanel: public vectorPanel{
ofParameter<float> text_speed;
ofParameter<float> text_scale;
ofParameter<bool> enable_anim;
- ofParameter<bool> spread_anim;
+ ofParameter<int> anim_style;
ofParameter<bool> anim_rev;
ofParameter<float> vert_pos;
ofParameter<float> vert_spread;
glyphbanner text;
+ vector<string> styles;
};
/*
class textgui : public ofxPanel{
diff --git a/nextus/src/vectorText.h b/nextus/src/vectorText.h
index f6c4df4..4fb7520 100644
--- a/nextus/src/vectorText.h
+++ b/nextus/src/vectorText.h
@@ -48,8 +48,9 @@ public:
float width;
};
-#define STYLE_SENTENCE 1
-#define STYLE_OVERLAPPING 2
+#define STYLE_WORDS 0
+#define STYLE_OVERLAPPING 1
+#define STYLE_SENTENCE 2
class glyphbanner{
ofXml SVGFont;
@@ -325,22 +326,26 @@ public:
int drawglyphs=0;
int drawlines=0;
+ float a=anim?reverse?1.0f-segment:segment:1.0;
+
switch (style){
- case STYLE_SENTENCE:{
- float p=((-width())/2);
+ case STYLE_WORDS:{
for (auto& w:words){
+ float p=(w.val*(2.0-w.width)); //was screen based now 2.0
+ float v=y+(vert_spread*w.val*(2.0)); //was screen based now 2.0
for (auto& g:w.glyphs){
if (w.amount>0.0f&&g.colour.getBrightness()>0){
+ drawglyphs++;
for (auto& o:g.outline){
+ drawlines++;
auto q=o;
- q.scale(s,-s);
- q.translate(glm::vec3((p*s)+x,y,0));
+ q.scale(s*a,-s*a);
+ q.translate(glm::vec3((p*s*a)+x,v,0));
outlines.push_back(colourPolyline(q,g.colour*w.amount));
}
}
- p+=g.width;
+ p+=g.width;
}
- p+=enspace;
}
break;
}
@@ -354,15 +359,33 @@ public:
for (auto& o:g.outline){
drawlines++;
auto q=o;
- float a=anim?reverse?1.0f-segment:segment:1.0;
q.scale(s*a,-s*a);
q.translate(glm::vec3((p*s*a)+x,v,0));
outlines.push_back(colourPolyline(q,g.colour*w.amount));
}
}
- p+=g.width*(anim?reverse?1.0f-segment:segment:1.0);
+ p+=g.width*(anim?a:1.0);
+ }
+ }
+ break;
+ }
+ case STYLE_SENTENCE:{
+ float p=((-width())/2);
+ for (auto& w:words){
+ for (auto& g:w.glyphs){
+ if (w.amount>0.0f&&g.colour.getBrightness()>0){
+ for (auto& o:g.outline){
+ auto q=o;
+ q.scale(s,-s);
+ q.translate(glm::vec3((p*s)+x,y,0));
+ outlines.push_back(colourPolyline(q,g.colour*w.amount));
+ }
+ }
+ p+=s*g.width;
}
+ p+=s*enspace;
}
+ break;
}
default:{
break;