差分
このページの2つのバージョン間の差分を表示します。
両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン 次のリビジョン両方とも次のリビジョン | ||
楽器をつくる:シーケンサ編 [2018/12/26 13:46] – [設計] baba | 楽器をつくる:シーケンサ編 [2020/06/20 11:22] – [ボタンのON/OFF切り替え] baba | ||
---|---|---|---|
行 106: | 行 106: | ||
} | } | ||
void update() | void update() | ||
- | { | + | { |
// マウスがボタン上にあるとき(ボタン押下処理) | // マウスがボタン上にあるとき(ボタン押下処理) | ||
- | if ( sqrt( pow(x-mouseX, | + | if ( dist(x, y, mouseX, mouseY) < size/2 ) { |
- | + | ||
// マウスボタンが押されている、且つ一つ前の状態では押されていなかったとき | // マウスボタンが押されている、且つ一つ前の状態では押されていなかったとき | ||
if ( mousePressed == true && previous_mousePressed == false) { | if ( mousePressed == true && previous_mousePressed == false) { | ||
status = !status; // falseならtrue, | status = !status; // falseならtrue, | ||
- | | + | |
// trueなら明るめのグレーにする | // trueなら明るめのグレーにする | ||
if( status == true ){ | if( status == true ){ | ||
行 124: | 行 124: | ||
} | } | ||
} | } | ||
- | | + | |
previous_mousePressed = mousePressed; | previous_mousePressed = mousePressed; | ||
} | } | ||
+ | |||
int x; // x座標 | int x; // x座標 | ||
int y; // y座標 | int y; // y座標 | ||
行 135: | 行 135: | ||
boolean previous_mousePressed; | boolean previous_mousePressed; | ||
} | } | ||
+ | |||
Button[] button = new Button[16]; | Button[] button = new Button[16]; | ||
- | + | ||
void setup() | void setup() | ||
- | { | + | { |
- | + | size(500, 500); | |
- | size(500, 500); | + | |
for ( int i = 0; i < 16; i++ ) { | for ( int i = 0; i < 16; i++ ) { | ||
button[i] = new Button(); | button[i] = new Button(); | ||
行 149: | 行 146: | ||
} | } | ||
} | } | ||
- | {{ : | ||
void draw() | void draw() | ||
{ | { | ||
行 160: | 行 156: | ||
</ | </ | ||
- | ここらで少しButtonクラスの記述が増えて来たので、別ファイルにクラスの記述を移します。クラスの記述部分をすべてButtonというタブに移します。 | + | ここらで少しButtonクラスの記述が増えて来たので、下記のスクリーンショットのようにクラスの記述を別ファイルに移します。クラスの記述部分をすべてButtonというタブに移します。 |
{{ : | {{ : |