Created
December 21, 2012 05:24
-
-
Save nappa7878/4350848 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
| // ********************************************** | |
| // 自動作成したな問題を | |
| // マウスクリックでランダム表示 | |
| // | |
| // ********************************************** | |
| //フォントを準備する | |
| PFont font = createFont("FFScale",32); | |
| //問題設定 | |
| String[] Qstr = new String[81]; | |
| //表示している問題番号 | |
| int Qcount = 0; | |
| void setup(){ | |
| size(640,480); | |
| colorMode(RGB,255); | |
| MakeQuestion(); | |
| //問題をバラバラにする | |
| RandQuestion(); | |
| } | |
| void draw(){ | |
| Question(); | |
| //ループを止める | |
| noLoop(); | |
| } | |
| void MakeQuestion(){ | |
| //作成する問題番号 | |
| int Mcount = 0; | |
| for(int j=0;j<9;j++){ | |
| for(int i=0;i<9;i++){ | |
| Qstr[Mcount] = (j+1) + "×" + (i+1); | |
| Mcount++; | |
| } | |
| } | |
| //i や j は 1 から始まってもよい | |
| // for(int j=1;j<10;j++){ | |
| // for(int i=1;i<10;i++){ | |
| // Qstr[Mcount] = j + "×" + i; | |
| // Mcount++; | |
| // } | |
| // } | |
| } | |
| void RandQuestion(){ | |
| //ダミー変数を用意します | |
| String dummy = ""; | |
| //1000回入れ替える | |
| for(int i=0;i<1000;i++){ | |
| //ランダムな2つの番号を準備します | |
| int rand1 = int(random(0, Qstr.length)); | |
| int rand2 = int(random(0, Qstr.length)); | |
| //2つの値を入れ替える | |
| dummy = Qstr[rand1]; | |
| Qstr[rand1] = Qstr[rand2]; | |
| Qstr[rand2] = dummy; | |
| } | |
| } | |
| void Question(){ | |
| background(255,255,255); | |
| fill(0,0,0); | |
| textFont(font,250); | |
| textAlign(CENTER,CENTER); | |
| text( Qstr[Qcount] ,width/2,height/2); | |
| } | |
| void mousePressed(){ | |
| //ループを始める | |
| loop(); | |
| Qcount++; | |
| if(Qcount>Qstr.length-1){ | |
| Qcount = 0; | |
| } | |
| //Qcount = Qcount % Qstr.length; //剰余 割り算の余り | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment