jsPsych/docs/demos/jspsych-reconstruction-demo1.html
2024-10-29 18:51:17 +00:00

51 lines
2.2 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<script src="docs-demo-timeline.js"></script>
<script src="https://unpkg.com/jspsych@8.0.3"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-button-response@2.0.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-html-keyboard-response@2.0.0"></script>
<script src="https://unpkg.com/@jspsych/plugin-reconstruction@2.0.0"></script>
<link rel="stylesheet" href="https://unpkg.com/jspsych@8.0.3/css/jspsych.css" />
<link rel="stylesheet" href="docs-demo.css" type="text/css" />
</head>
<body></body>
<script>
const jsPsych = initJsPsych();
const sample_function = function(param){
const size = 50 + Math.floor(param*250);
const html = '<div style="display: block; margin: auto; height: 300px; width: 300px; position: relative;">'+
'<div style="display: block; position: absolute; top: '+(150 - size/2)+'px; left:'+(150 - size/2)+'px; background-color: #000000; '+
'width: '+size+'px; height: '+size+'px;"></div></div><p>Press "h" to make the square larger. Press "g" to make the square smaller.</p>'+
'<p>When the square is the same size as the previous one, click Continue.</p>';
return html;
}
const match_item = {
type: jsPsychHtmlKeyboardResponse,
stimulus: '<div style="display: block; margin: auto; height: 300px; width: 300px; position: relative;">'+
'<div style="display: block; position: absolute; top: '+(150 - 210/2)+'px; left:'+(150 - 210/2)+'px; background-color: #000000; '+
'width: 210px; height: 210px;"></div></div>',
choices: ['c'],
post_trial_gap: 1250,
prompt: '<p>Study the size of this square carefully. On the next screen you will have to recreate it. When you are ready, press "c".</p>'
}
const reconstruction = {
type: jsPsychReconstruction,
stim_function: sample_function,
starting_value: 0.5,
}
const timeline = [match_item, reconstruction];
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>