mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
59 lines
2.0 KiB
HTML
59 lines
2.0 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<script src="docs-demo-timeline.js"></script>
|
|
<script src="https://unpkg.com/jspsych@7.2.2"></script>
|
|
<script src="https://unpkg.com/@jspsych/plugin-canvas-button-response@1.1.1"></script>
|
|
<script src="https://unpkg.com/@jspsych/plugin-html-button-response@1.1.1"></script>
|
|
<link rel="stylesheet" href="https://unpkg.com/jspsych@7.2.2/css/jspsych.css" />
|
|
<link rel="stylesheet" href="docs-demo.css" type="text/css" />
|
|
</head>
|
|
<body></body>
|
|
<script>
|
|
|
|
const jsPsych = initJsPsych();
|
|
|
|
// stimulus function that takes the canvas and additional parameters (radius, color)
|
|
// this can be called inside of an anonymous stimulus function, which takes the canvas (c) as its only argument
|
|
function filledCirc(canvas, radius, color) {
|
|
var ctx = canvas.getContext("2d");
|
|
ctx.beginPath();
|
|
ctx.arc(150, 150, radius, 0, 2 * Math.PI);
|
|
ctx.fillStyle = color;
|
|
ctx.fill();
|
|
}
|
|
|
|
const circle_1 = {
|
|
type: jsPsychCanvasButtonResponse,
|
|
stimulus: function(c) {
|
|
filledCirc(c, 100, 'blue');
|
|
},
|
|
canvas_size: [300, 300],
|
|
choices: ['Red', 'Green', 'Blue'],
|
|
prompt: '<p>What color is the circle?</p>',
|
|
data: {color: 'blue', radius: 100}
|
|
};
|
|
|
|
const circle_2 = {
|
|
type: jsPsychCanvasButtonResponse,
|
|
stimulus: function(c) {
|
|
filledCirc(c, 150, 'green');
|
|
},
|
|
canvas_size: [300, 300],
|
|
choices: ['Larger', 'Smaller'],
|
|
stimulus_duration: 1000,
|
|
prompt: '<p>Is this circle larger or smaller than the last one?</p>'+
|
|
'<p>Stimulus will be hidden after 1 second.</p>',
|
|
data: {color: 'green', radius: 150}
|
|
};
|
|
|
|
const timeline = [circle_1, circle_2];
|
|
|
|
if (typeof jsPsych !== "undefined") {
|
|
jsPsych.run(generateDocsDemoTimeline(timeline));
|
|
} else {
|
|
document.body.innerHTML = '<div style="text-align:center; margin-top:50%; transform:translate(0,-50%);">You must be online to view the plugin demo.</div>';
|
|
}
|
|
</script>
|
|
</html>
|