Created
August 7, 2012 15:18
-
-
Save arosh/3286305 to your computer and use it in GitHub Desktop.
ダミヤン識別
This file contains 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
// 起動時に呼び出される関数 | |
void setup() { | |
// ウィンドウのサイズ | |
size(720, 480); | |
// fps | |
// timer関数を呼んで時間経過を調べるほうが望ましいが、 | |
// 時間もあまりないので、0.05秒に1回draw()関数が呼ばれるのを利用した | |
frameRate(20); | |
// 背景色(灰色っぽい) | |
background(128); | |
// 文字のサイズ | |
textFont(loadFont("Osaka-20.vlw")); | |
// 変数の初期化(デフォルトでfalseになるとは思うが…) | |
isStarted = false; | |
lineCnt = -1; | |
} | |
// 経過時間を測るのに利用する変数(0.05秒に1回インクリメントする予定) | |
int timer; | |
// 測定が開始しているかどうか | |
boolean isStarted; | |
int lineCnt; | |
/* | |
0.05秒に1度、描画のために呼び出される関数 | |
音センサーの識別のためには12めもり必要である。 | |
[0]と[8]は必ずONで | |
[9], [10], [11]は必ずOFFである(1.5秒のスタート・ビット) | |
色々と楽をするために、4.5秒間(9めもり分)だけキー操作を取得することにした | |
ウィンドウが720pxで12めもり必要なので、 | |
1めもりあたり 720 / 12 = 60px | |
また、20fps -> 0.05s/frame -> 10frame / section -> 6px / frame | |
*/ | |
void draw() { | |
if(isStarted) timer++; | |
if(isStarted && timer >= 90) { | |
isStarted = false; | |
delay(1000); | |
} | |
// キーが押されている or マウスがクリックされている | |
else if (keyPressed || mousePressed) { | |
// マウスがクリックされている or ENTERキーが押されている or スペース・キーが押されている | |
if (mousePressed || | |
key == '\n' || | |
key == ' ') { | |
if (isStarted == false) { | |
isStarted = true; | |
timer = -1; | |
lineCnt++; | |
} | |
fill(255); | |
rect(6 * timer, lineCnt * 48, 6, 48); | |
} | |
else if (key == 'c') { | |
isStarted = false; | |
lineCnt = -1; | |
background(128); | |
} | |
} | |
// 横線 | |
for (int i = 1; i <= 9; i++) { | |
fill(255); | |
line(0, i * 48, 720, i * 48); | |
} | |
// 縦線 | |
for (int i = 1; i <= 11; i++) { | |
fill(255); | |
line(i * 60, 0, i * 60, 480); | |
} | |
text("push CLICK or ENTER or SPACE.(clear: c-key)", 20, 460); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment