-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMTA_EXP.pde
323 lines (284 loc) · 6.45 KB
/
MTA_EXP.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
import java.util.Collections;
Table table;
ArrayList<Condition> conditions = new ArrayList<Condition>();
int width = 900;
int height = 400;
int timestamp = 0;
int conditionNumber = 0;
int maxConditionNumber = 8;
int trial = 0;
int maxTrial = 35;
int success = -1;
int keyType = 0;
int startTime = 0;
int loopTime = 0;
int zone_time = loopTime - startTime;
boolean terminate = false;
boolean stopMoving = false;
Condition nowCondition;
Target nowTarget;
Zone nowZone;
class Condition {
int index;
int t_cue;
int t_zone;
int period;
Target target;
Zone zone;
Condition(int index, int t_cue, int t_zone, int period) {
this.index = index;
this.t_cue = t_cue;
this.t_zone = t_zone;
this.period = period;
}
}
class Target {
float velocity;
float ellipse_position;
float default_location;
float pixelvelocity;
Target (float velocity, float ellipse_position) {
this.velocity = velocity;
this.ellipse_position = ellipse_position;
this.default_location = ellipse_position;
}
void createTarget() {
fill(#FFFFFF);
ellipse(ellipse_position, height/2, 50, 50);
}
void move(float time) {
pixelvelocity = velocity*time;
ellipse_position += pixelvelocity;
}
void renew() {
ellipse_position = default_location;
}
}
class Zone {
int zone_position;
int zone_left;
int zone_width;
Zone (int x, int y) {
zone_left = x;
zone_width = y;
}
void createZone() {
fill(#320000);
rectMode(CORNERS);
rect(zone_left, 50, zone_width, height); //topleft, bottomright corner
}
void changeColor() {
fill(#00FF00);
rectMode(CORNERS);
rect(zone_left, 50, zone_width, height);
}
}
void settings() {
size(width, height, P2D);
pixelDensity(displayDensity());
}
void setup() {
frameRate(60);
initializeConditions();
initializeTable();
initializeDisplay();
}
void initializeConditions() {
conditions.add(new Condition(1, 0, 80, 1000));
conditions.add(new Condition(2, 0, 150, 1000));
conditions.add(new Condition(3, 0, 80, 1500));
conditions.add(new Condition(4, 0, 150, 1500));
conditions.add(new Condition(5, 100, 80, 1000));
conditions.add(new Condition(6, 100, 150, 1000));
conditions.add(new Condition(7, 100, 80, 1500));
conditions.add(new Condition(8, 100, 150, 1500));
Collections.shuffle(conditions);
}
void initializeTable() {
table = new Table();
table.addColumn("timestamp");
table.addColumn("cond");
table.addColumn("trial");
table.addColumn("success");
table.addColumn("t_cue");
table.addColumn("t_zone");
table.addColumn("p");
table.addColumn("key");
}
void initializeDisplay() {
float velocity;
int zoneLeft;
int zoneWidth;
int t_cue2;
int t_zone2;
for (int i=0; i<8; i++) {
Condition now = conditions.get(i);
t_cue2 = now.t_cue;
t_zone2 = now.t_zone;
if (t_cue2 == 0) {
if (t_zone2 == 80) {
zoneLeft = 0;
zoneWidth = 48;
}
else {
zoneLeft = 0;
zoneWidth = 90;
}
}
else {
if (t_zone2 == 80) {
zoneLeft = 60;
zoneWidth = 48;
}
else {
zoneLeft = 60;
zoneWidth = 90;
}
}
velocity = (float) zoneWidth/t_zone2;
Zone zone = new Zone(zoneLeft, zoneWidth);
now.zone = zone;
Target target;
if (t_cue2 == 0) {
target = new Target(velocity, 0);
}
else {
target = new Target(velocity, 60);
}
now.target = target;
}
}
void draw() {
checkTime();
background(#000000);
String label = "Remaining trials: " + (36 - trial) + " Condition: " + conditionNumber + " " + (keyType == 0 ? "keyPressed" : "keyReleased");
textSize(15);
fill(#FFFFFF);
text(label, 500, 30);
if (terminate) exit();
checkCondition();
nowTarget.move(timestamp);
display();
}
void checkCondition() {
if (nowCondition == null) {
nowCondition = conditions.get(conditionNumber);
nowTarget = nowCondition.target;
nowZone = nowCondition.zone;
conditionNumber ++;
return;
}
}
void checkTime() {
int nowTime = millis();
if (startTime == 0) {
startTime = nowTime;
timestamp = 0;
trial = 1;
return;
}
else {
timestamp = nowTime - startTime;
if (timestamp >= 1000) {
startTime = nowTime;
timestamp = 0;
checkTrial();
}
}
}
void display() {
nowZone.createZone();
if (!stopMoving) {
nowTarget.createTarget();
}
}
boolean assessResult(int loopTime) {
int gap = loopTime - startTime;
if (gap >= nowCondition.t_cue && gap <= (nowCondition.t_zone + nowCondition.t_cue)) {
success = 1;
return true;
}
else {
success = 0;
return false;
}
}
void keyPressed() {
loopTime = millis();
if (keyType == 0 && success == -1 && nowCondition != null && (loopTime - startTime <= nowCondition.period)) {
stopMoving = true;
if (assessResult (loopTime)) {
nowZone.changeColor();
}
inputToTable();
}
}
void keyReleased() {
loopTime = millis();
if (keyType == 1 && success == -1 && nowCondition != null && (loopTime - startTime <= nowCondition.period)) {
stopMoving = true;
if (assessResult(loopTime)) {
nowZone.changeColor();
}
inputToTable();
}
}
void inputToTable() {
TableRow newRow = table.addRow();
newRow.setInt("timestamp", (loopTime - startTime - nowCondition.t_cue));
newRow.setInt("cond", nowCondition.index);
newRow.setInt("trial", trial);
newRow.setInt("success", success);
newRow.setInt("t_cue", nowCondition.t_cue);
newRow.setInt("t_zone", nowCondition.t_zone);
newRow.setInt("p", nowCondition.period);
newRow.setInt("key", keyType);
}
void renewValues() {
loopTime = 0;
success = -1;
stopMoving = false;
}
void switchCondition() {
nowCondition = null;
trial = 1;;
renewValues();
delay(1000);
}
void switchKeyType() {
nowCondition = null;
conditionNumber = 0;
trial = 1;;
renewValues();
keyType = 1;
}
void checkTrial() {
if (success > -1) {
if (trial == maxTrial) {
if (keyType == 0) {
if (conditionNumber < maxConditionNumber) {
switchCondition();
}
else {
switchKeyType();
delay(3000);
}
}
else {
if (conditionNumber < maxConditionNumber) {
switchCondition();
}
else {
background(0);
saveTable(table, "2019199061.csv");
terminate = true;
}
}
}
else {
renewValues();
trial++;
}
}
nowTarget.renew();
}