-
Notifications
You must be signed in to change notification settings - Fork 0
/
ofApp.cpp
141 lines (105 loc) · 3.42 KB
/
ofApp.cpp
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
#include "ofApp.h"
//--------------------------------------------------------------
void ofApp::setup(){
//while(1){
ofSetWindowTitle("Voronoi_hunting");
ofBackground(255);
ofRectangle bounds = ofRectangle(10, 10, ofGetWidth() - 20, ofGetHeight() - 20);
//随机点
int agentTotal = 12;
int seed;
std::cout << "请输入1到50的随机整数用于生成随机agent" << endl;
std::cin >> seed;
std::cout << typeid(seed).name() << endl;
while (seed>50) {
std::cout << "请重新输入1到50的随机整数:";
std::cin >> seed;
}
ofSeedRandom(seed);
for (int i = 0; i < agentTotal; i++) {
ofDefaultVec3 newPoint = ofDefaultVec3(ofRandom(bounds.x, bounds.width), ofRandom(bounds.y, bounds.height), 0);
points.push_back(newPoint);
}
//ofApp::init_Voro(bounds, points);
//ofApp::generateVoro();
ofApp::update(bounds, points);
//ofApp::draw();
points.clear();
cout << "programe reached here" << endl;
for (auto cell : voronoi.getCells()) {
points.push_back(cell.centroid);
}
//}
}
//--------------------------------------------------------------
//void ofApp::init_Voro(ofRectangle bounds,vector<ofDefaultVec3> points) {
// //维诺图初始化
// voronoi.setBounds(bounds);
// voronoi.setPoints(points);
//}
//--------------------------------------------------------------
//void ofApp::generateVoro() {
// //维诺图生成
// voronoi.generate();
//}
//--------------------------------------------------------------
void ofApp::update(ofRectangle bounds, vector<ofDefaultVec3> points){
voronoi.setBounds(bounds);
voronoi.setPoints(points);
voronoi.generate();
}
//--------------------------------------------------------------
void ofApp::update() {
cout << "update22222" << endl;
voronoi.cal_neighbor();
voronoi.cal_up();
voronoi.update_point();
points = voronoi.getPoints();
voronoi.setPoints(points);
voronoi.generate();
voronoi.catchornot();
}
//--------------------------------------------------------------
void ofApp::draw(){
cout << "print!!!" << endl;
voronoi.draw();
}
//--------------------------------------------------------------
bool ofApp::isBorder(ofDefaultVec3 _pt) {
ofRectangle bounds = voronoi.getBounds();
return (_pt.x == bounds.x || _pt.x == bounds.x + bounds.width
|| _pt.y == bounds.y || _pt.y == bounds.y + bounds.height);
}
//--------------------------------------------------------------
void ofApp::keyPressed(int key){
}
//--------------------------------------------------------------
void ofApp::keyReleased(int key){
}
//--------------------------------------------------------------
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){
}