-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-functional-test.h
100 lines (79 loc) · 1.71 KB
/
1-functional-test.h
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
#include "ofMain.h"
#include <functional>
class Oscillator
{
protected:
typedef enum {
UPDATE_FN_0 = 0,
UPDATE_FN_1,
UPDATE_FN_2,
NUM_UPDATE_FN
} UpdateFnType;
function<void()> fn[NUM_UPDATE_FN];
UpdateFnType type;
void fn1() {
cout << __PRETTY_FUNCTION__ << endl;
ofDrawCircle(ofGetWidth()*0.5, ofGetHeight()*0.5, 100);
}
void fn2() {
cout << __PRETTY_FUNCTION__ << endl;
ofSetRectMode(OF_RECTMODE_CENTER);
ofDrawRectangle(ofGetWidth()*0.5, ofGetHeight()*0.5, 200, 200);
}
void fn3() {
cout << __PRETTY_FUNCTION__ << endl;
ofSetRectMode(OF_RECTMODE_CENTER);
ofDrawRectRounded(ofGetWidth()*0.5, ofGetHeight()*0.5, 200, 200, 50);
}
double t;
public:
Oscillator()
: type(UPDATE_FN_0)
{
// ポインタでも出来るけど、、、
fn[UPDATE_FN_0] = bind(mem_fn(&Oscillator::fn1), this);
fn[UPDATE_FN_1] = bind(mem_fn(&Oscillator::fn2), this);
fn[UPDATE_FN_2] = bind(mem_fn(&Oscillator::fn3), this);
}
void randomize() {
type = static_cast<UpdateFnType>(rand() % NUM_UPDATE_FN);
t = 1.;
}
void update() {
t *= 0.98;
}
void draw() {
ofPushStyle();
ofSetColor(250.*t, 50., 50.);
fn[type]();
ofPopStyle();
stringstream report;
report << "UpdateFnType: " << (type+1) << "/" << NUM_UPDATE_FN;
ofDrawBitmapStringHighlight(report.str(), 30, 30, ofColor::limeGreen);
}
};
class ofApp : public ofBaseApp
{
Oscillator oscllator;
public:
void setup() {
ofSetFrameRate(60);
}
void update() {
oscllator.update();
}
void draw() {
oscllator.draw();
}
void keyPressed(int key) {
if (key == ' ') {
oscllator.randomize();
}
}
};
#pragma mark -
#pragma mark main
int main(){
ofSetupOpenGL(500, 500, OF_WINDOW);
ofRunApp(new ofApp());
}