質問編集履歴
1
ソースコードの追加です
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,3 +1,449 @@
|
|
1
|
+
```processing
|
2
|
+
|
3
|
+
|
4
|
+
|
5
|
+
PImage img;
|
6
|
+
|
7
|
+
PrintWriter output;
|
8
|
+
|
9
|
+
String filename = nf(year(),4) + nf(month(),2) + nf(day(),2) + nf(hour(),2) + nf(minute(),2) ;
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
int ratio = 1; //サイズ比率
|
14
|
+
|
15
|
+
int angle;
|
16
|
+
|
17
|
+
int direction;
|
18
|
+
|
19
|
+
int baseTime;
|
20
|
+
|
21
|
+
int response;
|
22
|
+
|
23
|
+
int RT;
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
int i = 0;
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
boolean isDebug;
|
32
|
+
|
33
|
+
int numTrial;
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
int state;
|
38
|
+
|
39
|
+
int currentTrial; //実験が現在何試行目を実行中かを保持
|
40
|
+
|
41
|
+
PFont font;
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
void setup(){
|
46
|
+
|
47
|
+
background(128); //灰色);
|
48
|
+
|
49
|
+
size( 600, 600 );
|
50
|
+
|
51
|
+
frameRate(30);
|
52
|
+
|
53
|
+
noStroke();
|
54
|
+
|
55
|
+
|
56
|
+
|
57
|
+
state = 0;
|
58
|
+
|
59
|
+
baseTime = millis();
|
60
|
+
|
61
|
+
response = 0;
|
62
|
+
|
63
|
+
RT = 0;
|
64
|
+
|
65
|
+
|
66
|
+
|
67
|
+
textFont( createFont( "Georgia", 28 ) );
|
68
|
+
|
69
|
+
output = createWriter( filename + ".txt" );
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
}
|
74
|
+
|
75
|
+
|
76
|
+
|
77
|
+
void draw(){
|
78
|
+
|
79
|
+
//for(int i=0; i < 3; i++){
|
80
|
+
|
81
|
+
if( state == 0 ){
|
82
|
+
|
83
|
+
titlePhase();
|
84
|
+
|
85
|
+
}
|
86
|
+
|
87
|
+
else if( state == 1 ){
|
88
|
+
|
89
|
+
waitPhase();
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
else if(state == 2){
|
94
|
+
|
95
|
+
responsePhase();{
|
96
|
+
|
97
|
+
baseTime = millis(); // 削除するとインターバル時間を取れなくなる
|
98
|
+
|
99
|
+
}
|
100
|
+
|
101
|
+
}
|
102
|
+
|
103
|
+
else if(state == 3){
|
104
|
+
|
105
|
+
endPhase();
|
106
|
+
|
107
|
+
}
|
108
|
+
|
109
|
+
}
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
void titlePhase(){
|
116
|
+
|
117
|
+
//background(0,0,255); //青
|
118
|
+
|
119
|
+
background(255,255,255); //白
|
120
|
+
|
121
|
+
fill(255,0,0);
|
122
|
+
|
123
|
+
textSize(36);
|
124
|
+
|
125
|
+
text("START", 250, 225); // 表示するテキスト, x座標, y座標
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
int elapsedTime = millis() - baseTime;
|
130
|
+
|
131
|
+
if( elapsedTime > 3000 ){
|
132
|
+
|
133
|
+
state = 1;
|
134
|
+
|
135
|
+
}
|
136
|
+
|
137
|
+
|
138
|
+
|
139
|
+
}
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
void waitPhase(){
|
144
|
+
|
145
|
+
//background(255,128,128); //ピンク
|
146
|
+
|
147
|
+
background(255,255,255); //白
|
148
|
+
|
149
|
+
// check elapsed time to transit state
|
150
|
+
|
151
|
+
int time1 = millis() - baseTime;
|
152
|
+
|
153
|
+
if( time1 > 3000 ){
|
154
|
+
|
155
|
+
transitState();
|
156
|
+
|
157
|
+
}
|
158
|
+
|
159
|
+
}
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
void responsePhase(){
|
164
|
+
|
165
|
+
|
166
|
+
|
167
|
+
background(255,255,0); //黄色
|
168
|
+
|
169
|
+
noLoop();
|
170
|
+
|
171
|
+
img = loadImage("image1.png");
|
172
|
+
|
173
|
+
imageMode(CENTER);
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
int direction = (int)random(4);
|
178
|
+
|
179
|
+
if (direction == 0) {
|
180
|
+
|
181
|
+
angle = 0;
|
182
|
+
|
183
|
+
} else if (direction == 1) {
|
184
|
+
|
185
|
+
angle = 90;
|
186
|
+
|
187
|
+
} else if (direction == 2) {
|
188
|
+
|
189
|
+
angle = 180;
|
190
|
+
|
191
|
+
} else if (direction == 3){
|
192
|
+
|
193
|
+
angle = 270;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
ratio = (int)random(1,5);//サイズ 1倍から5倍までのランダム
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
pushMatrix();
|
202
|
+
|
203
|
+
translate(width/2, height/2);
|
204
|
+
|
205
|
+
rotate(radians(angle));
|
206
|
+
|
207
|
+
scale(ratio);
|
208
|
+
|
209
|
+
image(img, 0, 0);
|
210
|
+
|
211
|
+
popMatrix();
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
}
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
void endPhase(){
|
222
|
+
|
223
|
+
//background(0,0,255); //青
|
224
|
+
|
225
|
+
background(255,255,255); //白
|
226
|
+
|
227
|
+
fill(255,0,0);
|
228
|
+
|
229
|
+
textSize(36);
|
230
|
+
|
231
|
+
text("FINISH", 250, 225); // 表示するテキスト, x座標, y座標
|
232
|
+
|
233
|
+
}
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
void transitState(){
|
238
|
+
|
239
|
+
if( state == 1 ){
|
240
|
+
|
241
|
+
redraw();
|
242
|
+
|
243
|
+
state = 2;
|
244
|
+
|
245
|
+
}
|
246
|
+
|
247
|
+
else {
|
248
|
+
|
249
|
+
if( currentTrial == numTrial - 1 ){
|
250
|
+
|
251
|
+
state = 2;
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
else {
|
256
|
+
|
257
|
+
currentTrial++;
|
258
|
+
|
259
|
+
state = 1;
|
260
|
+
|
261
|
+
}
|
262
|
+
|
263
|
+
}
|
264
|
+
|
265
|
+
}
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
void keyPressed(){
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
if (key == ENTER || key == RETURN){
|
274
|
+
|
275
|
+
if( state == 0 ){
|
276
|
+
|
277
|
+
state = 1;
|
278
|
+
|
279
|
+
}
|
280
|
+
|
281
|
+
}
|
282
|
+
|
283
|
+
|
284
|
+
|
285
|
+
if( key == 'q' ){
|
286
|
+
|
287
|
+
output.flush();
|
288
|
+
|
289
|
+
output.close();
|
290
|
+
|
291
|
+
exit();
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
if (keyPressed == true){
|
298
|
+
|
299
|
+
|
300
|
+
|
301
|
+
if(i < 3){
|
302
|
+
|
303
|
+
if( state == 2 ){
|
304
|
+
|
305
|
+
loop();
|
306
|
+
|
307
|
+
state = 1;
|
308
|
+
|
309
|
+
i = i+1;
|
310
|
+
|
311
|
+
}
|
312
|
+
|
313
|
+
if (i >= 3){
|
314
|
+
|
315
|
+
state = 3;
|
316
|
+
|
317
|
+
//endPhase();
|
318
|
+
|
319
|
+
}
|
320
|
+
|
321
|
+
}
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
switch(keyCode) {
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
case UP:
|
332
|
+
|
333
|
+
if (angle == 0) {
|
334
|
+
|
335
|
+
|
336
|
+
|
337
|
+
println ("↑ hit" +" "+ (millis() - baseTime));
|
338
|
+
|
339
|
+
output.println("↑ hit" +" "+ (millis() - baseTime));
|
340
|
+
|
341
|
+
}
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
else {
|
346
|
+
|
347
|
+
println ("↑ miss" +" "+ (millis() - baseTime));
|
348
|
+
|
349
|
+
output.println("↑ miss" +" "+ (millis() - baseTime));
|
350
|
+
|
351
|
+
}
|
352
|
+
|
353
|
+
break;
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
case RIGHT:
|
358
|
+
|
359
|
+
if (angle == 90) {
|
360
|
+
|
361
|
+
println ("→ hit" +" "+ (millis() - baseTime));
|
362
|
+
|
363
|
+
output.println("→ hit" +" "+ (millis() - baseTime));
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
else {
|
368
|
+
|
369
|
+
println ("→ miss" +" "+ (millis() - baseTime));
|
370
|
+
|
371
|
+
output.println("→ miss" +" "+ (millis() - baseTime));
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
break;
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
case DOWN:
|
380
|
+
|
381
|
+
if (angle == 180) {
|
382
|
+
|
383
|
+
println ("↓ hit" +" "+ (millis() - baseTime));
|
384
|
+
|
385
|
+
output.println("↓ hit" +" "+ (millis() - baseTime));
|
386
|
+
|
387
|
+
}
|
388
|
+
|
389
|
+
else {
|
390
|
+
|
391
|
+
println ("↓ miss" +" "+ (millis() - baseTime));
|
392
|
+
|
393
|
+
output.println("↓ miss" +" "+ (millis() - baseTime));
|
394
|
+
|
395
|
+
}
|
396
|
+
|
397
|
+
break;
|
398
|
+
|
399
|
+
|
400
|
+
|
401
|
+
case LEFT:
|
402
|
+
|
403
|
+
if (angle == 270) {
|
404
|
+
|
405
|
+
println ("← hit" +" "+ (millis() - baseTime));
|
406
|
+
|
407
|
+
output.println("← hit" +" "+ (millis() - baseTime));
|
408
|
+
|
409
|
+
}
|
410
|
+
|
411
|
+
else {
|
412
|
+
|
413
|
+
println ("← miss" +" "+ (millis() - baseTime));
|
414
|
+
|
415
|
+
output.println("← miss" +" "+ (millis() - baseTime));
|
416
|
+
|
417
|
+
}
|
418
|
+
|
419
|
+
break;
|
420
|
+
|
421
|
+
}
|
422
|
+
|
423
|
+
}
|
424
|
+
|
425
|
+
|
426
|
+
|
427
|
+
|
428
|
+
|
429
|
+
void mousePressed(){ //マウスクリックでスタート
|
430
|
+
|
431
|
+
if (mousePressed == true){
|
432
|
+
|
433
|
+
if( state == 0 ){
|
434
|
+
|
435
|
+
state = 1;
|
436
|
+
|
437
|
+
}
|
438
|
+
|
439
|
+
}
|
440
|
+
|
441
|
+
}
|
442
|
+
|
443
|
+
```
|
444
|
+
|
445
|
+
|
446
|
+
|
1
447
|
お世話になります
|
2
448
|
|
3
449
|
|
@@ -15,3 +461,11 @@
|
|
15
461
|
3. 回転は任意の方向にメニューを作って1枚づつredrawでインターバルを2秒とって順番に表示させる。
|
16
462
|
|
17
463
|
4. 任意の回転メニューは3パターン用意する。
|
464
|
+
|
465
|
+
|
466
|
+
|
467
|
+
添付のコードは以前教えていただいたものを作りなおして、
|
468
|
+
|
469
|
+
エンターでスタート後、2秒ごとにランダムに矢印を表示して当たり判定をする内容になっております。
|
470
|
+
|
471
|
+
これを改修して今回質問の内容に持って行けないかと思っております。
|