Created
December 21, 2012 05:26
-
-
Save nappa7878/4350855 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]; | |
| String[] Astr = new String[81]; | |
| //表示している問題番号 | |
| int Qcount = 0; | |
| //表示モードの設定 | |
| int mode = 0; //0 問題 1 答え | |
| void setup(){ | |
| size(640,480); | |
| colorMode(RGB,255); | |
| MakeQandA(); | |
| //問題をバラバラにする | |
| RandQandA(); | |
| } | |
| void draw(){ | |
| switch(mode){ | |
| case 0: | |
| Question(); | |
| break; | |
| case 1: | |
| Answer(); | |
| break; | |
| } | |
| //ループを止める | |
| noLoop(); | |
| } | |
| void MakeQandA(){ | |
| //作成する問題番号 | |
| int Mcount = 0; | |
| for(int j=0;j<9;j++){ | |
| for(int i=0;i<9;i++){ | |
| Qstr[Mcount] = (j+1)*(i+1) + "÷" + (i+1); | |
| //答え | |
| Astr[Mcount] = str((j+1)); | |
| Mcount++; | |
| } | |
| } | |
| //j = 0、i = 0 のとき、Qstr[0] = (0+1) + "×" + (0+1) = "1×1" | |
| //j = 0、i = 1 のとき、Qstr[1] = (0+1) + "×" + (1+1) = "1×2" | |
| //j = 0、i = 2 のとき、Qstr[2] = (0+1) + "×" + (0+1) = "1×3" | |
| // | |
| //j = 1、i = 0 のとき、Qstr[9] = (1+1) + "×" + (0+1) = "2×1" | |
| //j = 1、i = 1 のとき、Qstr[10] = (1+1) + "×" + (1+1) = "2×2" | |
| // | |
| //j = 8、i = 8 のとき、Qstr[80] = (8+1) + "×" + (8+1) = "9×9" | |
| } | |
| void RandQandA(){ | |
| //ダミー変数を用意します | |
| 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)); | |
| //問題を入れ替える | |
| dummy = Qstr[rand1]; | |
| Qstr[rand1] = Qstr[rand2]; | |
| Qstr[rand2] = dummy; | |
| //答えを入れ替える | |
| dummy = Astr[rand1]; | |
| Astr[rand1] = Astr[rand2]; | |
| Astr[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 Answer(){ | |
| background(255,255,255); | |
| fill(0,0,255); //青 | |
| textFont(font,250); | |
| textAlign(CENTER,CENTER); | |
| text( Astr[Qcount] ,width/2,height/2); | |
| } | |
| void mousePressed(){ | |
| //ループを始める | |
| loop(); | |
| //表示モードを切り替える | |
| mode++; | |
| mode = mode % 2; | |
| //問題表示モード(mode = 0) | |
| if(mode == 0){ | |
| Qcount++; | |
| Qcount = Qcount % Qstr.length; | |
| } | |
| //Qcount = Qcount % Qstr.length; //剰余 割り算の余り | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment