summaryrefslogtreecommitdiff
path: root/nextus/src/vectorPlugin.h
blob: d71b8fad14829f68e249488870efd78368b5c62b (plain)
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
#pragma once

#include "ofMain.h"
#include "ofxGui.h"
#include "ofxSVG.h"
#include "ofxClipper.h"
#include "ofxPONK.h"
#include "lineTransformer.h"
#include "lineSegmenter.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);
		}
		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=getLines();
			for (auto& line:lines){
				line.draw();
			}
			ofPopMatrix();
			ofPopMatrix();
		}
		virtual vector<colourPolyline> getLines() {};
		virtual void update() {};

	protected:
		ofVec2f size;
		ofPoint position;
		ofxPanel panel;
};

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 svgPanel: public vectorPanel{
	public:
		svgPanel(
			string _title="",
			ofVec2f _size=DISPLAYSIZE,
			ofVec2f _pos=ofPoint(5,5)
			) : vectorPanel(_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(){
			timedelta=ofGetElapsedTimef()-last_frame_time;
			last_frame_time=ofGetElapsedTimef();
			phase=fmod(phase+(timedelta*segmenter_speed),1);
			while(phase<0) phase+=1.0f;
			//what's the issue with segmenter in reverse
			ofLog()<<"phase: "<<phase;
		}

	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;

		float last_frame_time, timedelta;
};