jsPsych/docs/demos/jspsych-canvas-slider-response-demo1.html
2022-03-13 15:31:28 +00:00

46 lines
1.5 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<script src="docs-demo-timeline.js"></script>
<script src="https://unpkg.com/jspsych@7.2.1"></script>
<script src="https://unpkg.com/@jspsych/plugin-canvas-slider-response@1.1.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-button-response@1.1.0"></script>
<link rel="stylesheet" href="https://unpkg.com/jspsych@7.2.1/css/jspsych.css" />
<link rel="stylesheet" href="docs-demo.css" type="text/css" />
</head>
<body></body>
<script>
const jsPsych = initJsPsych();
// Draw two squares
const colors = ['#FF3333', '#FF6A33'];
function twoSquares(c) {
const ctx = c.getContext('2d');
ctx.fillStyle = colors[0];
ctx.fillRect(200, 70, 40, 40);
ctx.fillStyle = colors[1];
ctx.fillRect(260, 70, 40, 40);
}
const trial = {
type: jsPsychCanvasSliderResponse,
stimulus: twoSquares,
labels: ['0','10'],
canvas_size: [150, 500],
prompt: '<p>How different would you say the colors of these two squares are on a scale from 0 (the same) to 10 (completely different)</p>',
data: {color1: colors[0], color2: colors[1]}
}
const timeline = [trial];
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>