| 打楽器コレクションを創ってみました
たくさんの音を扱いたいので
円の図形に音を関連付けた
オブジェクト(class)を創りました
創ったclassのコードは短いので
オープンしますね
//...bigin....................................................
class CiSoundButton {
float cx, cy, r;
color cl;
//String smname;
String str;
AudioSample sum;
CiSoundButton(float cx, float cy, float r, color cl, String str, AudioSample sum) {
this.cx=cx;this.cy=cy; this.r=r;
this.cl=cl;
this.sum=sum;
this.str=str;
}
void Draw() {
ellipseMode(CENTER);
stroke(0); fill(cl); ellipse(cx, cy, r, r);
textAlign(CENTER, CENTER);
float d=r/2 + 10;
textSize(12); fill(R); text(str, cx, cy+d);
}
boolean hitTest(float x, float y) {
if ( dist( x, y, cx, cy) < r/2 ) {
sum.trigger();
return true;
}
return false;
}
}
//...end....................................... |
|