Last active
November 1, 2020 16:59
-
-
Save nariakiiwatani/727d6fa8ab2303d11a0dd7f10a574488 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int x, y, index, posX[10], posY[10]; | |
// あとでiという変数を使うので、indexに改名しました。 | |
// iのままでも同じ動きをしますが、わかりにくくなるといけないので。 | |
//-------------------------------------------------------------- | |
void ofApp::setup() { | |
ofSetWindowShape(600, 400); | |
ofSetFrameRate(30); | |
ofSetBackgroundColor(255, 255, 255); | |
// indexの初期値をセット | |
index = 0; | |
} | |
//-------------------------------------------------------------- | |
void ofApp::update() { | |
} | |
//-------------------------------------------------------------- | |
void ofApp::draw(){ | |
// これだと0番目のひとつしか書かれないので | |
//posX[0] = 100; | |
//posY[0] = 300; | |
//ofSetColor(255, 0, 0); | |
//ofDrawCircle(posX[0], posY[0], 20); | |
// 10個書く | |
for(int i = 0; i < 10; ++i) { | |
ofSetColor(255, 0, 0); | |
ofDrawCircle(posX[i], posY[i], 20); | |
} | |
} | |
//-------------------------------------------------------------- | |
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) { | |
// ここでposXとposYを「宣言」してしまうと、「寿命」がこの関数内で終わる、 | |
// 1行目に書いたものとは別の「変数」になってしまうので、宣言しない。 | |
// int posX[10] = {X,X, X, X, X, X, X, X, X, X}; | |
// int posY[10] = {Y, Y, Y, Y, Y, Y, Y, Y, Y, Y}; | |
// こう書くと、1個の配列すべてに同じ座標(X,Y)が「代入」されてしまうので | |
// posX[1] = X; posY[1] = Y; | |
// posX[2] = X; posY[2] = Y; | |
// posX[3] = X; posY[3] = Y; | |
// posX[4] = X; posY[4] = Y; | |
// posX[5] = X; posY[5] = Y; | |
// posX[6] = X; posY[6] = Y; | |
// posX[7] = X; posY[7] = Y; | |
// posX[8] = X; posY[8] = Y; | |
// posX[9] = X; posY[9] = Y; | |
// index番目にだけ代入する | |
posX[index] = X; posY[index] = Y; | |
// 次回のクリックではindexが違う値になっていてほしいのでここで変える | |
index += 1; // 1増やす | |
// indexは0~9の範囲に収まっていてほしいので | |
// 10になったら0に戻す | |
if(index >= 10) { | |
index = 0; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment