Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change all_rAF_time.html timestamps #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions experiment/all_rAF_time.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@
var duration = 0;
var iti = 0;
var trials = 0;

var last_frame_time = 0;
var raf_start_time = 0;
var raf_current_time = 0;
var display_duration = 0;

document.querySelector('#start').addEventListener('click', beginExperiment);

Expand All @@ -34,17 +38,18 @@
}

function startTrial(ts) {
start_time = ts;
raf_start_time = performance.now();
last_frame_time = ts;
var html = '<div id="stim"></div>';
document.querySelector('body').innerHTML = html;
window.requestAnimationFrame(checkForTimeout);
}

function checkForTimeout(ts) {
var last_frame_duration = ts - last_frame_time;
raf_current_time = performance.now();
display_duration = raf_current_time - raf_start_time;
last_frame_duration = ts - last_frame_time;
last_frame_time = ts;
var display_duration = ts - start_time;
if(display_duration >= duration - (last_frame_duration/2)){
endTrial(ts);
} else {
Expand All @@ -55,18 +60,19 @@
function endTrial(ts) {
document.querySelector('#stim').remove();
trials--;
if(trials == 0){
if(trials === 0){
finishExperiment();
} else {
start_time = ts;
raf_start_time = performance.now();
window.requestAnimationFrame(checkForITI);
}
}

function checkForITI(ts) {
var last_frame_duration = ts - last_frame_time;
raf_current_time = performance.now();
display_duration = raf_current_time - raf_start_time;
last_frame_duration = ts - last_frame_time;
last_frame_time = ts;
var display_duration = ts - start_time;
if(display_duration >= iti - (last_frame_duration/2)){
startTrial(ts);
} else {
Expand Down