openFrameworksで、以下のようなサイン波を生成するコードを書きました。
C++
1//-------------------------------------------------------------- 2void ofApp::setup(){ 3 ofSetWindowShape(500, 500); 4 ofEnableSmoothing(); 5 ofNoFill(); 6 ofBackground(0, 0, 0); 7 ofSetFrameRate(60); 8} 9 10//-------------------------------------------------------------- 11void ofApp::update(){ 12 13} 14 15//-------------------------------------------------------------- 16void ofApp::draw(){ 17 ofBackground(0, 0, 0); 18 19 20 ofPath path = ofPath(); 21 22 path.setStrokeColor(ofColor(0, 0, 0)); 23 path.setStrokeWidth(1); 24 25 float angle = currentAngle; 26 float y = amplitude * sin(angle) + (ofGetWindowHeight()/2); 27 float x = 0.0; 28 29 if (x <= ofGetWindowWidth()) { 30 angle += angleStep; 31 float nextX = x + xStep; 32 float nextY = amplitude * sin(angle) + (ofGetWindowHeight()/2); 33 path.moveTo(x, y); 34 path.lineTo(nextX, nextY); 35 36 x = nextX; 37 y = nextY; 38 39 path.draw(); 40 path.close(); 41 42 cout << "in while" << endl; 43 } 44 45} 46 47void ofApp::updateCurrentAngle() { 48 currentAngle += angleSpeed; 49 if (currentAngle >= 2*PI) { 50 currentAngle -= 2*PI; 51 } 52}
しかしながら、ビルドしてみるとwindowが表示されません。
(while文の中のcoutは呼ばれているようです)
while文をコメントアウトしてビルドするとwindowは表示されるので、
while文が何かしらの原因だと思うのですが、よく原因がわかりません。
この現象をご存知の方がいらっしゃいましたら、ぜひご教授くださいませ。。。
あなたの回答
tips
プレビュー