mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-10 11:10:54 +00:00
WIP eye tracking demo
This commit is contained in:
parent
2cb45137ad
commit
462c262231
97
docs/demos/eye-tracking-with-webgazer.html
Normal file
97
docs/demos/eye-tracking-with-webgazer.html
Normal file
@ -0,0 +1,97 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/jspsych.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-preload.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-html-button-response.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-html-keyboard-response.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-image-keyboard-response.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-webgazer-init-camera.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-webgazer-calibrate.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/plugins/jspsych-webgazer-validate.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/examples/js/webgazer/webgazer.js"></script>
|
||||
<script src="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/extensions/jspsych-ext-webgazer.js"></script>
|
||||
<link
|
||||
rel="stylesheet"
|
||||
href="https://cdn.jsdelivr.net/gh/jspsych/jsPsych@6.3.1/css/jspsych.css"
|
||||
/>
|
||||
<style>
|
||||
.jspsych-btn {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body></body>
|
||||
<script>
|
||||
|
||||
var preload = {
|
||||
type: 'preload',
|
||||
images: ['img/blue.png']
|
||||
}
|
||||
|
||||
var start = {
|
||||
type: 'html-button-response',
|
||||
stimulus: '',
|
||||
choices: ['Run demo']
|
||||
};
|
||||
|
||||
var show_data = {
|
||||
type: 'html-button-response',
|
||||
stimulus: function() {
|
||||
var trial_data = jsPsych.data.getLastTrialData().values();
|
||||
var trial_json = JSON.stringify(trial_data, null, 2);
|
||||
return `<p style="margin-bottom:0px;"><strong>Trial data:</strong></p>
|
||||
<pre style="margin-top:0px;text-align:left;">${trial_json}</pre>`;
|
||||
},
|
||||
choices: ['Repeat demo']
|
||||
};
|
||||
|
||||
var init_camera = {
|
||||
type: 'webgazer-init-camera'
|
||||
}
|
||||
|
||||
var calibration = {
|
||||
type: 'webgazer-calibrate'
|
||||
}
|
||||
|
||||
var validation = {
|
||||
type: 'webgazer-validate'
|
||||
}
|
||||
|
||||
var begin = {
|
||||
type: 'html-keyboard-response',
|
||||
stimulus: 'Press any key to start.'
|
||||
}
|
||||
|
||||
var trial = {
|
||||
type: 'image-keyboard-response',
|
||||
stimulus: 'img/blue.png',
|
||||
choices: jsPsych.NO_KEYS,
|
||||
trial_duration: 1000,
|
||||
extensions: [
|
||||
{
|
||||
type: 'webgazer',
|
||||
params: {targets: ['#jspsych-image-keyboard-response-stimulus']}
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
var trial_loop = {
|
||||
timeline: [calibration, validation, begin, trial, show_data],
|
||||
loop_function: function() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
if (typeof jsPsych !== "undefined") {
|
||||
jsPsych.init({
|
||||
timeline: [preload, start, init_camera, trial_loop],
|
||||
extensions: [
|
||||
{type: 'webgazer'}
|
||||
]
|
||||
});
|
||||
} 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>
|
BIN
docs/demos/img/blue.png
Normal file
BIN
docs/demos/img/blue.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.1 KiB |
BIN
docs/demos/img/orange.png
Normal file
BIN
docs/demos/img/orange.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.2 KiB |
Loading…
Reference in New Issue
Block a user