1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
|
#pragma once
#include "ofMain.h"
#include "ofxGui.h"
#include "ofxSVG.h"
#include "ofxClipper.h"
#include "ofxPONK.h"
#include "lineTransformer.h"
#include "lineSegmenter.h"
#include "lineClipper.h"
#include "vectorText.h"
static ofVec2f DISPLAYSIZE(200,200);
class vectorPanel {
public:
vectorPanel(
string _title="",
ofVec2f _size=DISPLAYSIZE,
ofVec2f _pos=ofPoint(5,5))
{
size=_size;
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);
}
void draw(){
panel.draw();
ofPushMatrix();
ofTranslate(position);
ofSetColor(255);
ofNoFill();
ofDrawRectangle(0,0,size.x,size.y);
ofPushMatrix();
ofTranslate(size/2);
ofScale(DISPLAYSIZE.x/2.0f);
vector<colourPolyline> lines=clipOutput();
for (auto& line:lines){
line.draw();
}
ofPopMatrix();
ofPopMatrix();
}
vector<colourPolyline> clipOutput() {
ofLog()<<"frame has "<<frame.size()<<" paths";
return lineClipper::mask(getOutput(),ofRectangle(-1.0f,-1.0f,2.0f,2.0f));
};
vector<colourPolyline> getOutput() {return getLines();};
virtual vector<colourPolyline> getLines() {};
virtual void update() {};
protected:
ofVec2f size;
ofPoint position;
ofxPanel panel;
vector <ofPolyline> frame;
};
class defaultPanel: public vectorPanel{
//the minimum panel that can be instanced
public:
defaultPanel(
string _title="",
ofVec2f _size=DISPLAYSIZE,
ofVec2f _pos=ofPoint(5,5)
) : vectorPanel(_title,_size,_pos){}
vector<colourPolyline> getLines(){
vector<colourPolyline> output;
return output;
}
void update(){};
};
class transformPanel: public vectorPanel{
//a base class which supports transformation
public:
transformPanel(
string _title="",
ofVec2f _size=DISPLAYSIZE,
ofVec2f _pos=ofPoint(5,5)
) : vectorPanel(_title,_size,_pos){
origin=ofPoint(0,0);
rotation=0;
panel.add(use_rotate.set("rotate",false));
panel.add(rotation_delta.set("rotation",0.1,-2.0,2.0));
}
void update(){
timedelta=ofGetElapsedTimef()-last_frame_time;
last_frame_time=ofGetElapsedTimef();
if (use_rotate) rotation+=rotation_delta*timedelta;
};
vector<colourPolyline> getOutput(){
vector<colourPolyline> lines=getLines();
if (use_rotate){
ofMatrix4x4 rm = ofMatrix4x4::newIdentityMatrix();
rm.rotateRad(rotation,0,0,1);
//if (use_scale){
// rm.scale(scale_amt,scale_amt,scale_amt);
//}
//rm.translate(outputWindowSize.x/2,outputWindowSize.y/2,0);
vector<colourPolyline> transformedLines;
for (auto& line:lines){
transformedLines.push_back(lineTransformer::polyLineTransform(rm,line));
}
return transformedLines;
}
return lines;
};
protected:
ofPoint origin;
float rotation;
ofParameter<bool> use_rotate;
ofParameter<float> rotation_delta;
float last_frame_time, timedelta;
};
/*
next- enable transform offsets
crop for display
transformers
easy midi
*/
class svgPanel: public transformPanel{
public:
svgPanel(
string _title="",
ofVec2f _size=DISPLAYSIZE,
ofVec2f _pos=ofPoint(5,5)
) : transformPanel(_title,_size,_pos){
panel.add(shapeslabel.setup("SHAPES",""));
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));
panel.add(shapes_duration.set("duration",5.0,0,10.0));
panel.add(segmenterlabel.setup("SEGMENTER",""));
panel.add(use_segmenter.set("enable",false));
panel.add(segmenter_speed.set("speed",0.2,-1.0,1.0));
panel.add(segmenter_length.set("length",0.2,0.0,1.0));
panel.add(segmenter_number.set("number",1,1,8));
//shapes_generate.addListener(this,&svgPanel::generate_shapes);
}
void load(string filename);
void select_random_shapes();
void update_random_shapes(bool generate);
vector<colourPolyline> getAllLines();
vector<colourPolyline> getLines();
void update(){
transformPanel::update();
phase=fmod(phase+(timedelta*segmenter_speed),1);
while(phase<0) phase+=1.0f;
}
private:
//ofxFloatSlider contour_simplify;
ofxLabel shapeslabel;
//svg gui
ofParameter<bool> shapes_randomise;
ofxButton shapes_generate;
ofParameter<float> shapes_amount;
ofParameter<float> shapes_duration;
//ofxToggle use_mask;
//ofxToggle invert_mask;
//segmenter
ofxLabel segmenterlabel;
ofParameter<bool> use_segmenter;
//ofxToggle colour_segmenter;
ofParameter<float> segmenter_speed;
ofParameter<float> segmenter_length;
ofParameter<int> segmenter_number;
vector <colourLineSegmenter> segmenters;
vector <float> shape_selection_durations;
set <int> shape_selection;
int framecounter;
float phase; //,prev_time; //to calculate phase
//float rotate_amt;
//float scale_phase,scale_amt;
};
class textPanel: public vectorPanel{
public:
textPanel(
string _title="",
ofVec2f _size=DISPLAYSIZE,
ofVec2f _pos=ofPoint(5,5)
) : vectorPanel(_title,_size,_pos){
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_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_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");
}
void update(){
text.update();
}
vector<colourPolyline> getLines(){
vector<colourPolyline> shapes=text.getOutlines(
text_scale,
spread_anim?STYLE_OVERLAPPING:STYLE_SENTENCE,
0,0,
enable_anim,
anim_rev,
vert_spread,
use_beat,
beat_duration
);
//ofLog()<<"text returned "<<shapes.size()<<" lines";
return shapes;
}
void loadText(const string & f){
text.load(f);
}
void loadPalette(const string & f){
text.loadPalette(f);
}
void loadFont(const string & f){
text.loadFont(f);
}
protected:
ofParameter<bool> use_beat;
ofParameter<float> beat_duration;
ofParameter<float> text_speed;
ofParameter<float> text_scale;
ofParameter<bool> enable_anim;
ofParameter<bool> spread_anim;
ofParameter<bool> anim_rev;
ofParameter<float> vert_pos;
ofParameter<float> vert_spread;
glyphbanner text;
};
/*
class textgui : public ofxPanel{
public:
ofParameter<bool> use_beat;
ofParameter<float> beat_duration;
ofParameter<float> text_speed;
ofParameter<float> text_scale;
ofParameter<bool> enable_anim;
ofParameter<bool> anim_rev;
ofParameter<float> vert_pos;
ofParameter<float> vert_spread;
glyphbanner text;
int onset_frame;
void loadfile(const string & f){
if (!strcmp(strchr(f.c_str(), '\0') - 4, ".plt")){
text.loadPalette(f);
}
else {
text.load(f);
}
}
void setup(int x, int y){
//text.loadFont("fonts/EMSSpaceRocks.svg");
text.loadFont("fonts/EMSOsmotron.svg");
ofxPanel::setup("text","",x,y);
ofxPanel::add(use_beat.set("use beat", false));
ofxPanel::add(beat_duration.set("duration factor", 0.5f, 0.0f, 1.0f));
ofxPanel::add(text_speed.set("speed", 5.0f, 0.0f, 25.0f));
ofxPanel::add(text_scale.set("scale", 0.1f, 0.0f, 0.5f));
ofxPanel::add(enable_anim.set("animate", false));
ofxPanel::add(anim_rev.set("reverse", false));
ofxPanel::add(vert_pos.set("vert_pos", 0.0f, -0.3f, 0.3f));
ofxPanel::add(vert_spread.set("vert_spread", 0.0f, -0.3f, 0.3f));
}
void update(int oframe=0){
onset_frame=oframe;
text.update(text_speed,true);
}
void drawgui(int oframe=0){
onset_frame=oframe;
ofxPanel::draw();
}
void createWords(string t){
text.createWords(t);
}
vector<colourPolyline>& getOutlines(float x=0, float y=0){
return text.getOutlines(text_scale,STYLE_OVERLAPPING,x,y+(ofGetHeight()*vert_pos),enable_anim,anim_rev,vert_spread,use_beat,beat_duration);
}
};
*/
|