Skip to content

Instantly share code, notes, and snippets.

@nappa7878
Created February 3, 2013 06:54
Show Gist options
  • Save nappa7878/4700795 to your computer and use it in GitHub Desktop.
Save nappa7878/4700795 to your computer and use it in GitHub Desktop.
10000までの数
/*****************************************
* 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 );
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment