xxxxxxxxxx
174
let gui;
let b1;
let b2;
let b3;
let b4;
let b5;
const t0="赤";
const t1="黄";
const t2="緑";
const t3="青";
const t4="黒";
const texts = [t0, t1, t2, t3, t4];
let T; //文字設定
let C; //色設定
let uniqueArray = [0,1,2,3,4]; //回答用配列
//csvに書き込むためのtable
let table = new p5.Table();
table.addColumn('correct'); //答え
table.addColumn('answer'); //回答
let Time_min=3600; //60[fsp]*60[sec]
function setup() {
createCanvas(800, 600);
gui = createGui();
b1 = createButton(" ", 15, 450, 130, 100);
b2 = createButton(" ", 175, 450, 130, 100);
b3 = createButton(" ", 335, 450, 130, 100);
b4 = createButton(" ", 495, 450, 130, 100);
b5 = createButton(" ", 655, 450, 130, 100);
T=int(random(5));
C=int(random(5));
while(T==C)
C=int(random(5)); //色と文字が一緒にならないように
//ボタン色設定
b1.setStyle({fillBg:color_dec(0),fillBgHover:color_dec(0),textSize:40});
b2.setStyle({fillBg:color_dec(1),fillBgHover:color_dec(1),textSize:40});
b3.setStyle({fillBg:color_dec(2),fillBgHover:color_dec(2)});
b4.setStyle({fillBg:color_dec(3),fillBgHover:color_dec(3)});
b5.setStyle({fillBg:color_dec(4),fillBgHover:color_dec(4)});
}
function draw() {
background(240);
drawGui();
if(frameCount<=600){ //10秒経過
textSize(50);
fill(0);
textAlign(LEFT);
text("言葉が表す色を答えなさい",10,60);
}
textSize(200); //文字サイズ
textAlign(CENTER);
//Color = color_dec(C);
Text = texts[T];
fill(0); //文字の色
text(Text,400,330);
//text("■",400,330);
botten();
if(Time_min==frameCount){ //60秒経過
background(1);
noStroke();
fill(255);
textSize(200);
text("終了!", 400, 350);
final();
noLoop();
}
}
function GetRandom() {
let tmp=T
T=int(random(5));
while(tmp==T) //前の文字と被らないように
T=int(random(5));
tmp=C
C=int(random(5));
while(tmp==C || T==C) //前の色と文字に被らないように
C=int(random(5));
// 配列に0から4までの整数を格納するための配列
uniqueArray = [];
// print("***")
// print(uniqueArray);
// 配列に5つの異なる整数を格納する
while (uniqueArray.length < 5) {
let randomValue = int(random(5));
// すでに配列に存在しない場合に追加
if (!uniqueArray.includes(randomValue)) {
uniqueArray.push(randomValue);
}
}
b1.setStyle({fillBg:color_dec(uniqueArray[0]),fillBgHover:color_dec(uniqueArray[0])});
b2.setStyle({fillBg:color_dec(uniqueArray[1]),fillBgHover:color_dec(uniqueArray[1])});
b3.setStyle({fillBg:color_dec(uniqueArray[2]),fillBgHover:color_dec(uniqueArray[2])});
b4.setStyle({fillBg:color_dec(uniqueArray[3]),fillBgHover:color_dec(uniqueArray[3])});
b5.setStyle({fillBg:color_dec(uniqueArray[4]),fillBgHover:color_dec(uniqueArray[4])});
//b1.label=Text
//Table確認
// for (let i=0; i<table.getRowCount(); i++){
// for (let j=0; j<table.getColumnCount(); j++){
// print(table.getString(i,j));
// }
// print("------");
// }
}
function botten() {
if (b1.isPressed) {
let newRow = table.addRow();
newRow.setNum('correct', T);
newRow.setNum('answer', uniqueArray[0]);
GetRandom();
} else if (b2.isPressed) {
let newRow = table.addRow();
newRow.setNum('correct', T);
newRow.setNum('answer', uniqueArray[1]);
GetRandom();
} else if (b3.isPressed) {
let newRow = table.addRow();
newRow.setNum('correct', T);
newRow.setNum('answer', uniqueArray[2]);
GetRandom();
} else if (b4.isPressed) {
let newRow = table.addRow();
newRow.setNum('correct', T);
newRow.setNum('answer', uniqueArray[3]);
GetRandom();
} else if (b5.isPressed) {
let newRow = table.addRow();
newRow.setNum('correct', T);
newRow.setNum('answer', uniqueArray[4]);
GetRandom();
}
}
function color_dec(n){
const c0 = color(200, 0, 0); //赤
const c1 = color(255, 200, 0); //黄
const c2 = color(30, 140, 60); //緑
const c3 = color(20, 30, 180); //青
const c4 = color(0, 0, 0); //黒
const colors = [c0, c1, c2, c3, c4];
return colors[n];
}
function final(){
save(table, 'Stroop_1.csv'); //結果をダウンロード
}