-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
109 lines (92 loc) · 4.14 KB
/
index.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
<!DOCTYPE html>
<html lang="en" style="background: #C0C0C0;height: 100%;">
<head>
<title>bRMS example</title>
<meta charset="utf-8">
<script src="libs/jquery-min.js" type="text/javascript"></script>
<script src="libs/underscore-min.js" type="text/javascript"></script>
<script src="rms.js" type="text/javascript"></script>
<script src="jspsych.js" type="text/javascript"></script>
<script src="jspsych-brms.js" type="text/javascript"></script>
<link rel="stylesheet" href="css/jspsych.css" type="text/css"></link>
<script>
function download(filename, text) {
var element = document.createElement('a');
element.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(text));
element.setAttribute('download', filename);
element.style.display = 'none';
document.body.appendChild(element);
element.click();
document.body.removeChild(element);
}
// Shuffle list function
function shuffle(array) {
let currentIndex = array.length,
randomIndex;
// While there remain elements to shuffle...
while (currentIndex != 0) {
// Pick a remaining element...
let randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex--;
// And swap it with the current element.
[array[currentIndex], array[randomIndex]] = [
array[randomIndex], array[currentIndex]
];
}
return array;
}
function getRmsResults(data) {
correct = 0;
rt_sum = 0;
data.forEach((trial, i) => {
if (trial.correct) {
correct++;
rt_sum += trial.rt;
}
});
return [correct, rt_sum]
}
// Images path
const images = ["images/f42887_e_001.jpg", "images/f42887_e_005.jpg",
"images/f42887_e_015.jpg",
"images/f42887_e_025.jpg", "images/f42887_e_028.jpg", "images/f42887_e_053.jpg",
"images/f42887_e_058.jpg", "images/f42887_e_064.jpg", "images/f42887_e_072.jpg",
"images/f42887_e_080.jpg", "images/f42887_e_098.jpg", "images/f42887_e_103.jpg",
"images/f42887_e_121.jpg", "images/f42887_e_127.jpg", "images/f42887_e_140.jpg",
"images/f42887_e_156.jpg", "images/f42887_e_161.jpg", "images/f42887_e_180.jpg",
"images/f42887_e_202.jpg", "images/f42887_e_241.jpg", "images/f42887_e_001_1.jpg",
"images/f42887_e_005_1.jpg", "images/f42887_e_015_1.jpg", "images/f42887_e_025_1.jpg",
"images/f42887_e_028_1.jpg", "images/f42887_e_053_1.jpg", "images/f42887_e_058_1.jpg",
"images/f42887_e_064_1.jpg", "images/f42887_e_072_1.jpg", "images/f42887_e_080_1.jpg",
"images/f42887_e_098_1.jpg", "images/f42887_e_103_1.jpg", "images/f42887_e_121_1.jpg",
"images/f42887_e_127_1.jpg", "images/f42887_e_140_1.jpg", "images/f42887_e_156_1.jpg",
"images/f42887_e_161_1.jpg", "images/f42887_e_180_1.jpg", "images/f42887_e_202_1.jpg",
"images/f42887_e_241_1.jpg"
]
// Choices for RMS trials (q for left and p for right)
const choices = ["q", "p"];
let full_timeline = [];
shuffle(images).forEach(img => {
full_timeline.push({
type: "bRMS",
stimulus: [img],
choices: ["p", "q"],
post_trial_gap: 400,
stimulus_opacity: 0.3,
right_up: ['P'],
left_down: ['Q']
});
});
jsPsych.init({
timeline: full_timeline,
fullscreen: true,
on_finish: function() {
results = getRmsResults(jsPsych.data.get().values());
alert("You got " + results[0] + " correct out of " + full_timeline.length + " trials. Your average reaction time was " + Math.round(results[1] / results[0]) + " ms.");
}
});
</script>
</head>
<body>
</body>
</html>