-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCircles Exp.html
186 lines (164 loc) · 5.92 KB
/
Circles Exp.html
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
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="jspsych/jspsych.js"></script>
<script src="jspsych-psychophysics-master/jspsych-psychophysics-master/jspsych-psychophysics.js"></script>
<script src="jspsych/plugin-html-keyboard-response.js"></script>
<script src="jspsych/plugin-image-keyboard-response.js"></script>
<script src="jspsych/plugin-preload.js"></script>
<link href="jspsych/jspsych.css" rel="stylesheet" type="text/css" />
</head>
<body></body>
<script>
// test code for the stimuli
document.body.style.backgroundColor = "grey";
// Init jspsych
var jsPsych = initJsPsych({
on_finish:function(data) {
jsPsych.data.displayData();
},
override_safe_mode: true,
show_progress_bar: true
});
// Define timeline
var timeline = []
var preload = {
type: jsPsychPreload,
images: ['img/blue.png', 'img/orange.png']
};
timeline.push(preload);
//Welcome message
var welcome = {
type: jsPsychHtmlKeyboardResponse,
stimulus: "Welcome to the trial! Please press any key to begin the experiment."
};
timeline.push(welcome);
//Instructions
var instructions = {
type: jsPsychHtmlKeyboardResponse,
stimulus: `
<p>In this experiment, a circle will appear in the center
of the screen.</p><p>If the circle is <strong>blue</strong>,
press the letter F on the keyboard as fast as you can.</p>
<p>If the circle is <strong>orange</strong>, press the letter J
as fast as you can.</p>
<div style='width: 700px;'>
<div style='float: left;'><img src='img/blue.png'></img>
<p class='small'><strong>Press the F key</strong></p></div>
<div style='float: right;'><img src='img/orange.png'></img>
<p class='small'><strong>Press the J key</strong></p></div>
</div>
<p>Press any key to begin.</p>
`,
post_trial_gap: 2000
};
timeline.push(instructions);
// define fixation and circles using jspsych psychophysics
const blue_circle_object = {
obj_type: 'circle',
origin_center: true,
radius: 100,
line_color: 'blue',
fill_color: 'blue',
show_start_time: 500
};
const orange_circle_object = {
obj_type: 'circle',
origin_center: true,
radius: 100,
line_color: 'orange',
fill_color: 'orange',
show_start_time: 500
};
// Create Circles Array
var circles = [orange_circle_object, blue_circle_object];
// var shuffledCircles = jsPsych.randomization.repeat(circles, 3, true);
const fixation = {
obj_type: 'cross',
startX: 0,
startY: 0,
line_length: 50,
line_color: 'black',
origin_center: true,
show_end_time: 500
};
// Define Feedback
const fdbk = [
'<p style="font-size:300%;">Correct!</p>',
'<p style="font-size:300%;">Wrong response.</p>',
'<p style="font-size:300%;">End of the trial.</p>'
];
// Define Keys
const keys = ['f', 'j'];
// Define Feedback Display
var fdbkDisplay = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function() {
if (jsPsych.data.getLastTrialData().values()[0].correct == true) {
return fdbk[0]
} else if (jsPsych.data.getLastTrialData().values()[0].correct == false) {
return fdbk[1]
} else {
return fdbk[2]
}
},
choices: 'NO_KEYS',
trial_duration: 500,
on_finish: function(data) {
var correct = null;
}
};
// Define trials
var trial = {
timeline: [
{
type: jsPsychPsychophysics,
stimuli: [fixation, jsPsych.timelineVariable('circles')]}, fdbkDisplay
],
choices: ['f', 'j'],
response_type: 'key',
timeline_variables: [
{circles: circles[0]},
{circles: circles[1]}
],
randomize_order: true,
repetitions: 5,
data: {
task: 'response',
correct_response: jsPsych.timelineVariable('correct_response')
},
on_finish: function(data) {
var correct = null;
if(jsPsych.timelineVariable('circles') == blue_circle_object && jsPsych.pluginAPI.compareKeys(data.response, keys[0]) ||
jsPsych.timelineVariable('circles') == orange_circle_object && jsPsych.pluginAPI.compareKeys(data.response, keys[1])) {
correct = true
} else if (jsPsych.timelineVariable('circles') == blue_circle_object && jsPsych.pluginAPI.compareKeys(data.response, keys[1]) ||
jsPsych.timelineVariable('circles') == orange_circle_object && jsPsych.pluginAPI.compareKeys(data.response, keys[0])) {
correct = false
}
data.correct = correct;
}
};
// Define Debrief Block
const debrief = {
type: jsPsychHtmlKeyboardResponse,
stimulus: function() {
var trials = jsPsych.data.get().filter({trial_type: 'psychophysics'});
var correct_trials = trials.filter({correct: true});
var accuracy = Math.round(correct_trials.count() / trials.count() * 100);
var rt = Math.round(correct_trials.select('rt').mean());
return `<p>You responded correctly on ${accuracy}% of the trials.</p>
<p>Your average response time was ${rt}ms.</p>
<p>Press any key to complete the experiment. Thank you!</p>`;
},
on_finish: function(data) {
var correct = null;
}
};
timeline.push(trial);
timeline.push(fdbkDisplay)
timeline.push(debrief)
jsPsych.run(timeline)
</script>
</html>