Last active
December 11, 2015 08:08
-
-
Save nappa7878/4570878 to your computer and use it in GitHub Desktop.
Processingで書かれたコード
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 cx=800, cy=600; //画面の大きさ | |
| //旗画像の設定 | |
| int flagMax = 40; | |
| String[] flagImage = new String[flagMax]; | |
| PImage img; | |
| String imagePreLoad=""; | |
| int flg=-1; //フラッグ | |
| int ktimer; //固視点時間計測用 | |
| int trl=1; //現在の試行回数(1から始まる) | |
| int timer; //反応時間計測用 | |
| boolean endflag = false; //終了フラッグ | |
| int score = 0; //正解数 | |
| int Qmax = 50; //問題数 | |
| int randNum=0;//ランダムな旗番号 | |
| int randRotate=0;//ランダムな回転角度 | |
| int randScale=0;//正像と鏡像 | |
| PFont fnt=createFont("FFScala", 32); | |
| void setup() { | |
| size(cx,cy); | |
| colorMode(RGB, 255); | |
| smooth(); | |
| //旗データの作成 | |
| for(int i=0;i<40;i++){ | |
| flagImage[i] = "data/flag_"+(i+1)+".png"; | |
| } | |
| /* @pjs | |
| preload = "data/flag_1.png,data/flag_2.png,data/flag_3.png,data/flag_4.png,data/flag_5.png,data/flag_6.png,data/flag_7.png,data/flag_8.png,data/flag_9.png,data/flag_10.png, | |
| data/flag_11.png,data/flag_12.png,data/flag_13.png,data/flag_14.png,data/flag_15.png,data/flag_16.png,data/flag_17.png,data/flag_18.png,data/flag_19.png,data/flag_20.png, | |
| data/flag_21.png,data/flag_22.png,data/flag_23.png,data/flag_24.png,data/flag_25.png,data/flag_26.png,data/flag_27.png,data/flag_28.png,data/flag_29.png,data/flag_30.png, | |
| data/flag_31.png,data/flag_32.png,data/flag_33.png,data/flag_34.png,data/flag_35.png,data/flag_36.png,data/flag_37.png,data/flag_38.png,data/flag_39.png,data/flag_40.png | |
| " | |
| */ | |
| } | |
| void draw(){ | |
| background(128); | |
| if (flg == -1){ | |
| StartMessage(); | |
| } | |
| if (flg==0) { | |
| //表示 | |
| PlusDraw(); //固視点 | |
| ktimer = millis(); | |
| flg++; | |
| } | |
| else if(flg == 1) { | |
| //表示 | |
| PlusDraw(); //固視点 | |
| ScoreDraw(); //スコアー | |
| //1秒間呈示 | |
| if(millis()-ktimer>=1000){ | |
| flg++; | |
| } | |
| }else if(flg == 2) { | |
| randNum = int(random(0,flagMax)); | |
| randRotate = 20*int(random(1,18)); | |
| randScale = int(random(0,2)); | |
| //表示 | |
| QnumDraw(); //問題番号 | |
| Flag1Draw(); //旗 | |
| Flag2Draw(); | |
| ScoreDraw(); //スコアー | |
| //反応時間計測 | |
| timer = millis(); | |
| flg++; | |
| }else if(flg==3) { | |
| //表示 | |
| QnumDraw(); //問題番号 | |
| Flag1Draw(); //旗 | |
| Flag2Draw(); | |
| ScoreDraw(); //スコアー | |
| }else if(flg==4) { | |
| flg = 0; | |
| trl++; | |
| if (trl>Qmax){ | |
| flg = 5; | |
| } | |
| }else if(flg==5){ | |
| //終了メッセージ | |
| EndMessage(); | |
| if(endflag){ | |
| goodSnd.close(); | |
| badSnd.close(); | |
| minim.stop(); | |
| super.stop(); | |
| exit(); | |
| } | |
| } | |
| } | |
| //固視点 | |
| void PlusDraw(){ | |
| pushMatrix(); | |
| translate(cx/2, cy/2); | |
| fill(255, 255, 255); | |
| textFont(fnt, 100); | |
| textAlign(CENTER); | |
| text("+", 0, 0); | |
| popMatrix(); | |
| } | |
| //問題番号 | |
| void QnumDraw(){ | |
| pushMatrix(); | |
| translate(0, 0); | |
| fill(255, 255, 255); | |
| textFont(fnt, 36); | |
| textAlign(LEFT); | |
| text("Question No. = "+trl, 30, 50); | |
| popMatrix(); | |
| } | |
| //旗 | |
| void Flag1Draw(){ | |
| pushMatrix(); | |
| translate(width / 4, height / 2); | |
| img = loadImage(flagImage[randNum]); | |
| image(img, -img.width/2, -img.height/2); | |
| popMatrix(); | |
| } | |
| void Flag2Draw(){ | |
| pushMatrix(); | |
| translate(width * 3 / 4, height / 2); | |
| //randScale=0のとき正像、scale(1, 1) randScale=1のとき鏡像、scale(-1, 1) | |
| scale(1-2*randScale, 1); | |
| rotate(radians(randRotate)); | |
| image(img, -img.width/2, -img.height/2); | |
| popMatrix(); | |
| } | |
| //スコア | |
| void ScoreDraw(){ | |
| pushMatrix(); | |
| translate(cx/2, cy/2); | |
| fill(255, 255, 255); | |
| textAlign(CENTER); | |
| textFont(fnt, 36); | |
| text("Score = "+score, 0, 250); | |
| popMatrix(); | |
| } | |
| //開始メッセージ | |
| void StartMessage(){ | |
| pushMatrix(); | |
| translate(cx/2, cy/2); | |
| noStroke(); | |
| fill(255, 255, 255, 200); | |
| rect(-300, -100, 600, 200); | |
| fill(0, 0, 255); | |
| textFont(fnt, 36); | |
| textAlign(CENTER, CENTER); | |
| text("一致ならば「J」キー、\n不一致ならば「F」キー\n(開始:マウスクリック)",0,0); | |
| popMatrix(); | |
| } | |
| //終了メッセージ | |
| void EndMessage(){ | |
| pushMatrix(); | |
| translate(cx/2, cy/2); | |
| noStroke(); | |
| fill(255, 255, 255, 200); | |
| rect(-300, -100, 600, 200); | |
| fill(0, 0, 255); | |
| textFont(fnt, 36); | |
| textAlign(CENTER); | |
| text("YourScore = "+score+"\n(スペースキーを押してください)", 0, 0); | |
| popMatrix(); | |
| } | |
| void keyPressed(){ | |
| if (key == 'j' || key == 'f'){ //キーが j か f の時しか反応しない | |
| if (flg == 3){ | |
| flg++; | |
| if(randScale == 0 && key == 'j'){ | |
| score++; | |
| goodSnd.trigger(); | |
| }else if(randScale == 1 && key == 'f'){ | |
| score++; | |
| goodSnd.trigger(); | |
| }else{ | |
| badSnd.trigger(); | |
| } | |
| } | |
| }else if((flg == 5) && (key == ' ')){ | |
| endflag = true; | |
| } | |
| } | |
| void mousePressed(){ | |
| if(flg == -1){ | |
| flg = 0; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment