-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperiment.html
98 lines (85 loc) · 3.59 KB
/
experiment.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
<!DOCTYPE html>
<html>
<head>
<title>My experiment</title>
<script src="jspsych-6.1.0/jspsych.js"></script>
<script src="jspsych-6.1.0/plugins/jspsych-html-keyboard-response.js"></script>
<script src="jspsych-6.1.0/plugins/jspsych-image-keyboard-response.js"></script>
<link href="jspsych-6.1.0/css/jspsych.css" rel="stylesheet" type="text/css"></link>
</head>
<body></body>
<script>
/* create timeline */
var timeline = [];
/* define welcome message trial */
var welcome = {
type: "html-keyboard-response",
stimulus: "Welcome to the experiment. Press any key to begin."
};
timeline.push(welcome);
var instructions = {
type: "html-keyboard-response",
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 class='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>"
};
timeline.push(instructions);
// fixtion frame
var fixation = {
type: 'html-keyboard-response',
stimulus: '<div style="font-size:60px;">+</div>',
choices: jsPsych.NO_KEYS,
trial_duration: function(){
return jsPsych.randomization.sampleWithoutReplacement([250, 500, 750, 1000, 1250, 1500, 1750, 2000], 1)[0];
},
data: {test_part: 'fixation'}
}
// stimuli (stimulus determines the trial number)
var test_stimuli = [
{ t_stimulus: "img/blue.png", data: {test_part: 'test', correct_response: 'f'}},
{ t_stimulus: "img/orange.png", data: {test_part: 'test', correct_response: 'j'}}
];
var test = {
type: "image-keyboard-response",
stimulus: jsPsych.timelineVariable('t_stimulus'),
choices: ['f', 'j'],
data: jsPsych.timelineVariable('data'),
on_finish: function(data){
data.correct = data.key_press == jsPsych.pluginAPI.convertKeyCharacterToKeyCode(data.correct_response);
// data.rt = data.time_elapsed - jsPsych.data.get().last(2).values()[0].time_elapsed;
console.log(jsPsych.data.get().last(2).values()[0])
console.log(jsPsych.data.get().last(1).values()[0])
}
}
// timeline for one trial
var test_procedure = {
timeline: [fixation, test],
timeline_variables: test_stimuli,
randomize_order: true,
repetitions: 1
}
timeline.push(test_procedure)
// finishing
var finishing = {
type: "html-keyboard-response",
stimulus: "<p>Congratulations! You have finished this task.</p>" +
"<p>Press any key to begin.</p>"
};
timeline.push(finishing);
var subj_id = jsPsych.randomization.randomID(15);
/* start the experiment */
jsPsych.init({
timeline: timeline,
on_finish: function(){jsPsych.data.get().localSave('csv','Pilot_data'+subj_id+'.csv');}
});
</script>
</html>