10000までの数がランダムに表示されます。一斉授業で大きな声で読ませる練習をすればよいでしょう。
ちょっと工夫したのは、0のある桁をどう表示させるかです。
パターンは次のように8通りあります。(×が0のあるところ)
- ●●●●
- ●×××
- ●××●
- ●×●×
- ●●××
- ●×●●
- ●●×●
- ●●●×
画面の中央あたりをクリックすると、この8通りをランダムに表示します。
数字もランダムですよ。
よく見ると薄く画面の左側にボタンが8つ表示されています。
これは8つのパターンと一致しています。
ここをクリックすると、そのパターンの問題だけが表示されます。
子どもたちの様子を見ながら出題パターンを変えることができます。
このソースは、iPad用です。
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
/***************************************** | |
* 10000までの数(iPad用) | |
* | |
* Hiroyuki Nakano | |
* 2013.2.3 | |
*****************************************/ | |
//フォントの設定 | |
PFont font=createFont("FFScala", 32); | |
PFont font1=createFont("MS Gothic", 32); | |
//問題の種類 | |
int Qmode = 0; | |
//ボタンの設定 | |
RectButton[] rectBtn; | |
String rectBtnName[] = {"●●●●","●×××","●××●","●×●×","●●××","●×●●","●●×●","●●●×"}; | |
//初期設定をする | |
void setup(){ | |
size(screen.width, screen.height); | |
colorMode(RGB, 255); | |
//ボタンの定義 | |
color buttoncolor = color(220); | |
color highlight = color(250); | |
rectBtn = new RectButton[rectBtnName.length]; | |
for(int i=0;i<rectBtnName.length;i++){ | |
rectBtn[i] = new RectButton(10, 50+85*i, 60, 75, rectBtnName[i], buttoncolor, highlight); | |
} | |
} | |
//描画を繰り返す | |
void draw(){ | |
Question(); | |
for(int i=0;i<rectBtnName.length;i++){ | |
rectBtn[i].display(); | |
} | |
noLoop(); | |
} | |
//問題を表示する | |
void Question(){ | |
int sen = 0; | |
int hyaku = 0; | |
int ju = 0; | |
int iti = 0; | |
String Qstr = ""; | |
switch(Qmode){ | |
case 0: | |
sen = int(random(1, 10)); | |
hyaku =int(random(1, 10)); | |
ju = int(random(1, 10)); | |
iti = int(random(1, 10)); | |
Qstr = str(sen) + str(hyaku) + str(ju) + str(iti); | |
break; | |
case 1: | |
sen = int(random(1, 10)); | |
hyaku =0; | |
ju = 0; | |
iti = 0; | |
Qstr = str(sen) + str(hyaku) + str(ju) + str(iti); | |
break; | |
case 2: | |
sen = int(random(1, 10)); | |
hyaku =0; | |
ju = 0; | |
iti = int(random(1, 10)); | |
Qstr = str(sen) + str(hyaku) + str(ju) + str(iti); | |
break; | |
case 3: | |
sen = int(random(1, 10)); | |
hyaku =0; | |
ju = int(random(1, 10)); | |
iti = 0; | |
Qstr = str(sen) + str(hyaku) + str(ju) + str(iti); | |
break; | |
case 4: | |
sen = int(random(1, 10)); | |
hyaku =int(random(1, 10)); | |
ju = 0; | |
iti = 0; | |
Qstr = str(sen) + str(hyaku) + str(ju) + str(iti); | |
break; | |
case 5: | |
sen = int(random(1, 10)); | |
hyaku = 0; | |
ju = int(random(1, 10)); | |
iti = int(random(1, 10)); | |
Qstr = str(sen) + str(hyaku) + str(ju) + str(iti); | |
break; | |
case 6: | |
sen = int(random(1, 10)); | |
hyaku =int(random(1, 10)); | |
ju = 0; | |
iti = int(random(1, 10)); | |
Qstr = str(sen) + str(hyaku) + str(ju) + str(iti); | |
break; | |
case 7: | |
sen = int(random(1, 10)); | |
hyaku =int(random(1, 10)); | |
ju = int(random(1, 10)); | |
iti = 0; | |
Qstr = str(sen) + str(hyaku) + str(ju) + str(iti); | |
break; | |
} | |
background(255, 255, 255); | |
fill(0, 0, 0); | |
textFont(font, 400); | |
textAlign(CENTER, CENTER); | |
text( Qstr, width / 2 + 50, height / 2); | |
} | |
//マウスクリック時の処理 | |
void mousePressed(){ | |
Qmode = int(random(0, 8)); | |
for(int i=0;i<rectBtnName.length;i++){ | |
if(rectBtn[i].pressed()) { | |
Qmode = i; | |
break; | |
} | |
} | |
loop(); | |
} | |
class Button | |
{ | |
int x, y; | |
int wsize, hsize; | |
String wstr; | |
color buttoncolor,textcolor; | |
boolean pressed = false; | |
boolean pressed() { | |
if (mouseX >= x && mouseX <= x+wsize && | |
mouseY >= y && mouseY <= y+hsize) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
} | |
class RectButton extends Button{ | |
RectButton(int ix, int iy, int iwsize , int ihsize , String istr , color ibuttoncolor, color itextcolor) | |
{ | |
x = ix; | |
y = iy; | |
wsize = iwsize; | |
hsize = ihsize; | |
wstr = istr; | |
buttoncolor = ibuttoncolor; | |
textcolor = itextcolor; | |
} | |
void display() { | |
noStroke(); | |
fill(buttoncolor); | |
rect(x, y, wsize, hsize); | |
fill(textcolor); | |
textFont(font1, 12); | |
text(wstr, x + wsize / 2, y + hsize /2 ); | |
} | |
} |