Commit 571f201e authored by Thomas Pronk's avatar Thomas Pronk

_

parent 391b347d
No preview for this file type
......@@ -41,6 +41,10 @@ flowScheduler.add(webcam_trialRoutineEnd());
flowScheduler.add(intro_calibatrion_trialRoutineBegin());
flowScheduler.add(intro_calibatrion_trialRoutineEachFrame());
flowScheduler.add(intro_calibatrion_trialRoutineEnd());
const trialsLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(trialsLoopBegin, trialsLoopScheduler);
flowScheduler.add(trialsLoopScheduler);
flowScheduler.add(trialsLoopEnd);
flowScheduler.add(quitPsychoJS, '', true);
// quit if user presses Cancel in dialog box:
......@@ -50,6 +54,7 @@ psychoJS.start({
expName: expName,
expInfo: expInfo,
resources: [
{'name': 'calibration_trials.xlsx', 'path': 'calibration_trials.xlsx'}
]
});
......@@ -83,6 +88,9 @@ var mouse;
var intro_calibatrion_trialClock;
var text_2;
var mouse_2;
var calibration_trialClock;
var calibration_square;
var mouse_3;
var globalClock;
var routineTimer;
function experimentInit() {
......@@ -136,6 +144,21 @@ function experimentInit() {
win: psychoJS.window,
});
mouse_2.mouseClock = new util.Clock();
// Initialize components for Routine "calibration_trial"
calibration_trialClock = new util.Clock();
calibration_square = new visual.Rect ({
win: psychoJS.window, name: 'calibration_square',
width: [0.02, 0.02][0], height: [0.02, 0.02][1],
ori: 0, pos: [0, 0],
lineWidth: 0, lineColor: new util.Color([1, 1, 1]),
fillColor: new util.Color([1, 1, 1]),
opacity: 1, depth: 0, interpolate: true,
});
mouse_3 = new core.Mouse({
win: psychoJS.window,
});
mouse_3.mouseClock = new util.Clock();
// Create some handy timers
globalClock = new util.Clock(); // to track the time since experiment started
routineTimer = new util.CountdownTimer(); // to track time remaining of each (non-slip) routine
......@@ -471,6 +494,169 @@ function intro_calibatrion_trialRoutineEnd(snapshot) {
}
var trials;
var currentLoop;
function trialsLoopBegin(trialsLoopScheduler) {
// set up handler to look after randomisation of conditions etc
trials = new TrialHandler({
psychoJS: psychoJS,
nReps: 1, method: TrialHandler.Method.RANDOM,
extraInfo: expInfo, originPath: undefined,
trialList: 'calibration_trials.xlsx',
seed: undefined, name: 'trials'
});
psychoJS.experiment.addLoop(trials); // add the loop to the experiment
currentLoop = trials; // we're now the current loop
// Schedule all the trials in the trialList:
trials.forEach(function() {
const snapshot = trials.getSnapshot();
trialsLoopScheduler.add(importConditions(snapshot));
trialsLoopScheduler.add(calibration_trialRoutineBegin(snapshot));
trialsLoopScheduler.add(calibration_trialRoutineEachFrame(snapshot));
trialsLoopScheduler.add(calibration_trialRoutineEnd(snapshot));
trialsLoopScheduler.add(endLoopIteration(trialsLoopScheduler, snapshot));
});
return Scheduler.Event.NEXT;
}
function trialsLoopEnd() {
psychoJS.experiment.removeLoop(trials);
return Scheduler.Event.NEXT;
}
var calibration_trialComponents;
function calibration_trialRoutineBegin(snapshot) {
return function () {
//------Prepare to start Routine 'calibration_trial'-------
t = 0;
calibration_trialClock.reset(); // clock
frameN = -1;
// update component parameters for each repeat
calibration_square.setPos([0, 0]);
// setup some python lists for storing info about the mouse_3
mouse_3.clicked_name = [];
gotValidClick = false; // until a click is received
// keep track of which components have finished
calibration_trialComponents = [];
calibration_trialComponents.push(calibration_square);
calibration_trialComponents.push(mouse_3);
calibration_trialComponents.forEach( function(thisComponent) {
if ('status' in thisComponent)
thisComponent.status = PsychoJS.Status.NOT_STARTED;
});
return Scheduler.Event.NEXT;
};
}
function calibration_trialRoutineEachFrame(snapshot) {
return function () {
//------Loop for each frame of Routine 'calibration_trial'-------
let continueRoutine = true; // until we're told otherwise
// get current time
t = calibration_trialClock.getTime();
frameN = frameN + 1;// number of completed frames (so 0 is the first frame)
// update/draw components on each frame
// *calibration_square* updates
if (t >= 0.0 && calibration_square.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
calibration_square.tStart = t; // (not accounting for frame time here)
calibration_square.frameNStart = frameN; // exact frame index
calibration_square.setAutoDraw(true);
}
// *mouse_3* updates
if (t >= 0.0 && mouse_3.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
mouse_3.tStart = t; // (not accounting for frame time here)
mouse_3.frameNStart = frameN; // exact frame index
mouse_3.status = PsychoJS.Status.STARTED;
mouse_3.mouseClock.reset();
prevButtonState = mouse_3.getPressed(); // if button is down already this ISN'T a new click
}
if (mouse_3.status === PsychoJS.Status.STARTED) { // only update if started and not finished!
let buttons = mouse_3.getPressed();
if (!buttons.every( (e,i,) => (e == prevButtonState[i]) )) { // button state changed?
prevButtonState = buttons;
if (buttons.reduce( (e, acc) => (e+acc) ) > 0) { // state changed to a new click
// check if the mouse was inside our 'clickable' objects
gotValidClick = false;
for (const obj of [calibration_square]) {
if (obj.contains(mouse_3)) {
gotValidClick = true;
mouse_3.clicked_name.push(obj.name)
}
}
if (gotValidClick === true) { // abort routine on response
continueRoutine = false;
}
}
}
}
// check for quit (typically the Esc key)
if (psychoJS.experiment.experimentEnded || psychoJS.eventManager.getKeys({keyList:['escape']}).length > 0) {
return quitPsychoJS('The [Escape] key was pressed. Goodbye!', false);
}
// check if the Routine should terminate
if (!continueRoutine) { // a component has requested a forced-end of Routine
return Scheduler.Event.NEXT;
}
continueRoutine = false; // reverts to True if at least one component still running
calibration_trialComponents.forEach( function(thisComponent) {
if ('status' in thisComponent && thisComponent.status !== PsychoJS.Status.FINISHED) {
continueRoutine = true;
}
});
// refresh the screen if continuing
if (continueRoutine) {
return Scheduler.Event.FLIP_REPEAT;
} else {
return Scheduler.Event.NEXT;
}
};
}
function calibration_trialRoutineEnd(snapshot) {
return function () {
//------Ending Routine 'calibration_trial'-------
calibration_trialComponents.forEach( function(thisComponent) {
if (typeof thisComponent.setAutoDraw === 'function') {
thisComponent.setAutoDraw(false);
}
});
// store data for thisExp (ExperimentHandler)
const xys = mouse_3.getPos();
const buttons = mouse_3.getPressed();
psychoJS.experiment.addData('mouse_3.x', xys[0]);
psychoJS.experiment.addData('mouse_3.y', xys[1]);
psychoJS.experiment.addData('mouse_3.leftButton', buttons[0]);
psychoJS.experiment.addData('mouse_3.midButton', buttons[1]);
psychoJS.experiment.addData('mouse_3.rightButton', buttons[2]);
if (mouse_3.clicked_name.length > 0) {
psychoJS.experiment.addData('mouse_3.clicked_name', mouse_3.clicked_name[0]);}
// the Routine "calibration_trial" was not non-slip safe, so reset the non-slip timer
routineTimer.reset();
return Scheduler.Event.NEXT;
};
}
function endLoopIteration(scheduler, snapshot) {
// ------Prepare for next entry------
return function () {
......
......@@ -51,6 +51,10 @@ flowScheduler.add(webcam_trialRoutineEnd());
flowScheduler.add(intro_calibatrion_trialRoutineBegin());
flowScheduler.add(intro_calibatrion_trialRoutineEachFrame());
flowScheduler.add(intro_calibatrion_trialRoutineEnd());
const trialsLoopScheduler = new Scheduler(psychoJS);
flowScheduler.add(trialsLoopBegin, trialsLoopScheduler);
flowScheduler.add(trialsLoopScheduler);
flowScheduler.add(trialsLoopEnd);
flowScheduler.add(quitPsychoJS, '', true);
// quit if user presses Cancel in dialog box:
......@@ -60,6 +64,7 @@ psychoJS.start({
expName: expName,
expInfo: expInfo,
resources: [
{'name': 'calibration_trials.xlsx', 'path': 'calibration_trials.xlsx'}
]
});
......@@ -93,6 +98,9 @@ var mouse;
var intro_calibatrion_trialClock;
var text_2;
var mouse_2;
var calibration_trialClock;
var calibration_square;
var mouse_3;
var globalClock;
var routineTimer;
function experimentInit() {
......@@ -146,6 +154,21 @@ function experimentInit() {
win: psychoJS.window,
});
mouse_2.mouseClock = new util.Clock();
// Initialize components for Routine "calibration_trial"
calibration_trialClock = new util.Clock();
calibration_square = new visual.Rect ({
win: psychoJS.window, name: 'calibration_square',
width: [0.02, 0.02][0], height: [0.02, 0.02][1],
ori: 0, pos: [0, 0],
lineWidth: 0, lineColor: new util.Color([1, 1, 1]),
fillColor: new util.Color([1, 1, 1]),
opacity: 1, depth: 0, interpolate: true,
});
mouse_3 = new core.Mouse({
win: psychoJS.window,
});
mouse_3.mouseClock = new util.Clock();
// Create some handy timers
globalClock = new util.Clock(); // to track the time since experiment started
routineTimer = new util.CountdownTimer(); // to track time remaining of each (non-slip) routine
......@@ -478,6 +501,167 @@ function intro_calibatrion_trialRoutineEnd(snapshot) {
}
var trials;
var currentLoop;
function trialsLoopBegin(trialsLoopScheduler) {
// set up handler to look after randomisation of conditions etc
trials = new TrialHandler({
psychoJS: psychoJS,
nReps: 1, method: TrialHandler.Method.RANDOM,
extraInfo: expInfo, originPath: undefined,
trialList: 'calibration_trials.xlsx',
seed: undefined, name: 'trials'
});
psychoJS.experiment.addLoop(trials); // add the loop to the experiment
currentLoop = trials; // we're now the current loop
// Schedule all the trials in the trialList:
for (const thisTrial of trials) {
const snapshot = trials.getSnapshot();
trialsLoopScheduler.add(importConditions(snapshot));
trialsLoopScheduler.add(calibration_trialRoutineBegin(snapshot));
trialsLoopScheduler.add(calibration_trialRoutineEachFrame(snapshot));
trialsLoopScheduler.add(calibration_trialRoutineEnd(snapshot));
trialsLoopScheduler.add(endLoopIteration(trialsLoopScheduler, snapshot));
}
return Scheduler.Event.NEXT;
}
function trialsLoopEnd() {
psychoJS.experiment.removeLoop(trials);
return Scheduler.Event.NEXT;
}
var calibration_trialComponents;
function calibration_trialRoutineBegin(snapshot) {
return function () {
//------Prepare to start Routine 'calibration_trial'-------
t = 0;
calibration_trialClock.reset(); // clock
frameN = -1;
// update component parameters for each repeat
calibration_square.setPos([0, 0]);
// setup some python lists for storing info about the mouse_3
mouse_3.clicked_name = [];
gotValidClick = false; // until a click is received
// keep track of which components have finished
calibration_trialComponents = [];
calibration_trialComponents.push(calibration_square);
calibration_trialComponents.push(mouse_3);
for (const thisComponent of calibration_trialComponents)
if ('status' in thisComponent)
thisComponent.status = PsychoJS.Status.NOT_STARTED;
return Scheduler.Event.NEXT;
};
}
function calibration_trialRoutineEachFrame(snapshot) {
return function () {
//------Loop for each frame of Routine 'calibration_trial'-------
let continueRoutine = true; // until we're told otherwise
// get current time
t = calibration_trialClock.getTime();
frameN = frameN + 1;// number of completed frames (so 0 is the first frame)
// update/draw components on each frame
// *calibration_square* updates
if (t >= 0.0 && calibration_square.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
calibration_square.tStart = t; // (not accounting for frame time here)
calibration_square.frameNStart = frameN; // exact frame index
calibration_square.setAutoDraw(true);
}
// *mouse_3* updates
if (t >= 0.0 && mouse_3.status === PsychoJS.Status.NOT_STARTED) {
// keep track of start time/frame for later
mouse_3.tStart = t; // (not accounting for frame time here)
mouse_3.frameNStart = frameN; // exact frame index
mouse_3.status = PsychoJS.Status.STARTED;
mouse_3.mouseClock.reset();
prevButtonState = mouse_3.getPressed(); // if button is down already this ISN'T a new click
}
if (mouse_3.status === PsychoJS.Status.STARTED) { // only update if started and not finished!
let buttons = mouse_3.getPressed();
if (!buttons.every( (e,i,) => (e == prevButtonState[i]) )) { // button state changed?
prevButtonState = buttons;
if (buttons.reduce( (e, acc) => (e+acc) ) > 0) { // state changed to a new click
// check if the mouse was inside our 'clickable' objects
gotValidClick = false;
for (const obj of [calibration_square]) {
if (obj.contains(mouse_3)) {
gotValidClick = true;
mouse_3.clicked_name.push(obj.name)
}
}
if (gotValidClick === true) { // abort routine on response
continueRoutine = false;
}
}
}
}
// check for quit (typically the Esc key)
if (psychoJS.experiment.experimentEnded || psychoJS.eventManager.getKeys({keyList:['escape']}).length > 0) {
return quitPsychoJS('The [Escape] key was pressed. Goodbye!', false);
}
// check if the Routine should terminate
if (!continueRoutine) { // a component has requested a forced-end of Routine
return Scheduler.Event.NEXT;
}
continueRoutine = false; // reverts to True if at least one component still running
for (const thisComponent of calibration_trialComponents)
if ('status' in thisComponent && thisComponent.status !== PsychoJS.Status.FINISHED) {
continueRoutine = true;
break;
}
// refresh the screen if continuing
if (continueRoutine) {
return Scheduler.Event.FLIP_REPEAT;
} else {
return Scheduler.Event.NEXT;
}
};
}
function calibration_trialRoutineEnd(snapshot) {
return function () {
//------Ending Routine 'calibration_trial'-------
for (const thisComponent of calibration_trialComponents) {
if (typeof thisComponent.setAutoDraw === 'function') {
thisComponent.setAutoDraw(false);
}
}
// store data for thisExp (ExperimentHandler)
const xys = mouse_3.getPos();
const buttons = mouse_3.getPressed();
psychoJS.experiment.addData('mouse_3.x', xys[0]);
psychoJS.experiment.addData('mouse_3.y', xys[1]);
psychoJS.experiment.addData('mouse_3.leftButton', buttons[0]);
psychoJS.experiment.addData('mouse_3.midButton', buttons[1]);
psychoJS.experiment.addData('mouse_3.rightButton', buttons[2]);
if (mouse_3.clicked_name.length > 0) {
psychoJS.experiment.addData('mouse_3.clicked_name', mouse_3.clicked_name[0]);}
// the Routine "calibration_trial" was not non-slip safe, so reset the non-slip timer
routineTimer.reset();
return Scheduler.Event.NEXT;
};
}
function endLoopIteration(scheduler, snapshot) {
// ------Prepare for next entry------
return function () {
......
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
This experiment was created using PsychoPy3 Experiment Builder (v2020.2.0),
on August 07, 2020, at 09:01
If you publish work using this script the most relevant publication is:
Peirce J, Gray JR, Simpson S, MacAskill M, Höchenberger R, Sogo H, Kastman E, Lindeløv JK. (2019)
PsychoPy2: Experiments in behavior made easy Behav Res 51: 195.
https://doi.org/10.3758/s13428-018-01193-y
"""
from __future__ import absolute_import, division
from psychopy import locale_setup
from psychopy import prefs
from psychopy import sound, gui, visual, core, data, event, logging, clock
from psychopy.constants import (NOT_STARTED, STARTED, PLAYING, PAUSED,
STOPPED, FINISHED, PRESSED, RELEASED, FOREVER)
import numpy as np # whole numpy lib is available, prepend 'np.'
from numpy import (sin, cos, tan, log, log10, pi, average,
sqrt, std, deg2rad, rad2deg, linspace, asarray)
from numpy.random import random, randint, normal, shuffle
import os # handy system and path functions
import sys # to get file system encoding
from psychopy.hardware import keyboard
ale
# Ensure that relative paths start from the same directory as this script
_thisDir = os.path.dirname(os.path.abspath(__file__))
os.chdir(_thisDir)
# Store info about the experiment session
psychopyVersion = '2020.2.0'
expName = 'demo_eye_tracking' # from the Builder filename that created this script
expInfo = {'participant': '', 'session': '001'}
dlg = gui.DlgFromDict(dictionary=expInfo, sort_keys=False, title=expName)
if dlg.OK == False:
core.quit() # user pressed cancel
expInfo['date'] = data.getDateStr() # add a simple timestamp
expInfo['expName'] = expName
expInfo['psychopyVersion'] = psychopyVersion
# Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc
filename = _thisDir + os.sep + u'data/%s_%s_%s' % (expInfo['participant'], expName, expInfo['date'])
# An ExperimentHandler isn't essential but helps with data saving
thisExp = data.ExperimentHandler(name=expName, version='',
extraInfo=expInfo, runtimeInfo=None,
originPath='C:\\DATA\\REPOS\\GitHub\\e2e_psychojs\\tech_demos\\demo_eye_tracking\\demo_eye_tracking_lastrun.py',
savePickle=True, saveWideText=True,
dataFileName=filename)
# save a log file for detail verbose info
logFile = logging.LogFile(filename+'.log', level=logging.EXP)
logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file
endExpNow = False # flag for 'escape' or other condition => quit the exp
frameTolerance = 0.001 # how close to onset before 'same' frame
# Start Code - component code to be run before the window creation
# Setup the Window
win = visual.Window(
size=(1024, 768), fullscr=True, screen=0,
winType='pyglet', allowGUI=False, allowStencil=False,
monitor='testMonitor', color=[0,0,0], colorSpace='rgb',
blendMode='avg', useFBO=True,
units='height')
# store frame rate of monitor if we can measure it
expInfo['frameRate'] = win.getActualFrameRate()
if expInfo['frameRate'] != None:
frameDur = 1.0 / round(expInfo['frameRate'])
else:
frameDur = 1.0 / 60.0 # could not measure, so guess
# create a default keyboard (e.g. to check for escape)
defaultKeyboard = keyboard.Keyboard()
# Initialize components for Routine "loading_trial"
loading_trialClock = core.Clock()
text = visual.TextStim(win=win, name='text',
text='Downloading additional resources. \n\nOne moment please...',
font='Arial',
pos=(0, 0), height=0.1, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=-1.0);
# Initialize components for Routine "webcam_trial"
webcam_trialClock = core.Clock()
intro_text = visual.TextStim(win=win, name='intro_text',
text='demo_eye_tracking: starting webcam\n\nThis experiment demonstrates eye tracking via the webgazer library. \n\nYou should see your web-browser request access to your webcam. Please permit this and wait a little while.\n\nOnce you see see your webcam video in the top-left of the screen, click anywhere to continue...',
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=0.0);
mouse = event.Mouse(win=win)
x, y = [None, None]
mouse.mouseClock = core.Clock()
# Initialize components for Routine "intro_calibatrion_trial"
intro_calibatrion_trialClock = core.Clock()
text_2 = visual.TextStim(win=win, name='text_2',
text="demo_eye_tracking: calibatrion\n\nNow we'll calibrate the eye tracker. Please try to keep your head still and within the rectangle you see in your webcam video. When you do so, the rectangle turns green.\n\nIn the next part of this experiment, white squares appears at different locations on the screen. Please click each square with your mouse.\n\nClick anywhere to continue...",
font='Arial',
pos=(0, 0), height=0.04, wrapWidth=None, ori=0,
color='white', colorSpace='rgb', opacity=1,
languageStyle='LTR',
depth=0.0);
mouse_2 = event.Mouse(win=win)
x, y = [None, None]
mouse_2.mouseClock = core.Clock()
# Create some handy timers
globalClock = core.Clock() # to track the time since experiment started
routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine
# ------Prepare to start Routine "loading_trial"-------
continueRoutine = True
# update component parameters for each repeat
# keep track of which components have finished
loading_trialComponents = [text]
for thisComponent in loading_trialComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
loading_trialClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "loading_trial"-------
while continueRoutine:
# get current time
t = loading_trialClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=loading_trialClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *text* updates
if text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
text.frameNStart = frameN # exact frame index
text.tStart = t # local t and not account for scr refresh
text.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(text, 'tStartRefresh') # time at next scr refresh
text.setAutoDraw(True)
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in loading_trialComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "loading_trial"-------
for thisComponent in loading_trialComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
thisExp.addData('text.started', text.tStartRefresh)
thisExp.addData('text.stopped', text.tStopRefresh)
# the Routine "loading_trial" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# ------Prepare to start Routine "webcam_trial"-------
continueRoutine = True
# update component parameters for each repeat
# setup some python lists for storing info about the mouse
gotValidClick = False # until a click is received
# keep track of which components have finished
webcam_trialComponents = [intro_text, mouse]
for thisComponent in webcam_trialComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
webcam_trialClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "webcam_trial"-------
while continueRoutine:
# get current time
t = webcam_trialClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=webcam_trialClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *intro_text* updates
if intro_text.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
intro_text.frameNStart = frameN # exact frame index
intro_text.tStart = t # local t and not account for scr refresh
intro_text.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(intro_text, 'tStartRefresh') # time at next scr refresh
intro_text.setAutoDraw(True)
# *mouse* updates
if mouse.status == NOT_STARTED and t >= 0.0-frameTolerance:
# keep track of start time/frame for later
mouse.frameNStart = frameN # exact frame index
mouse.tStart = t # local t and not account for scr refresh
mouse.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(mouse, 'tStartRefresh') # time at next scr refresh
mouse.status = STARTED
mouse.mouseClock.reset()
prevButtonState = mouse.getPressed() # if button is down already this ISN'T a new click
if mouse.status == STARTED: # only update if started and not finished!
buttons = mouse.getPressed()
if buttons != prevButtonState: # button state changed?
prevButtonState = buttons
if sum(buttons) > 0: # state changed to a new click
# abort routine on response
continueRoutine = False
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in webcam_trialComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "webcam_trial"-------
for thisComponent in webcam_trialComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
thisExp.addData('intro_text.started', intro_text.tStartRefresh)
thisExp.addData('intro_text.stopped', intro_text.tStopRefresh)
# store data for thisExp (ExperimentHandler)
x, y = mouse.getPos()
buttons = mouse.getPressed()
thisExp.addData('mouse.x', x)
thisExp.addData('mouse.y', y)
thisExp.addData('mouse.leftButton', buttons[0])
thisExp.addData('mouse.midButton', buttons[1])
thisExp.addData('mouse.rightButton', buttons[2])
thisExp.addData('mouse.started', mouse.tStart)
thisExp.addData('mouse.stopped', mouse.tStop)
thisExp.nextEntry()
# the Routine "webcam_trial" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# ------Prepare to start Routine "intro_calibatrion_trial"-------
continueRoutine = True
# update component parameters for each repeat
# setup some python lists for storing info about the mouse_2
gotValidClick = False # until a click is received
# keep track of which components have finished
intro_calibatrion_trialComponents = [text_2, mouse_2]
for thisComponent in intro_calibatrion_trialComponents:
thisComponent.tStart = None
thisComponent.tStop = None
thisComponent.tStartRefresh = None
thisComponent.tStopRefresh = None
if hasattr(thisComponent, 'status'):
thisComponent.status = NOT_STARTED
# reset timers
t = 0
_timeToFirstFrame = win.getFutureFlipTime(clock="now")
intro_calibatrion_trialClock.reset(-_timeToFirstFrame) # t0 is time of first possible flip
frameN = -1
# -------Run Routine "intro_calibatrion_trial"-------
while continueRoutine:
# get current time
t = intro_calibatrion_trialClock.getTime()
tThisFlip = win.getFutureFlipTime(clock=intro_calibatrion_trialClock)
tThisFlipGlobal = win.getFutureFlipTime(clock=None)
frameN = frameN + 1 # number of completed frames (so 0 is the first frame)
# update/draw components on each frame
# *text_2* updates
if text_2.status == NOT_STARTED and tThisFlip >= 0.0-frameTolerance:
# keep track of start time/frame for later
text_2.frameNStart = frameN # exact frame index
text_2.tStart = t # local t and not account for scr refresh
text_2.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(text_2, 'tStartRefresh') # time at next scr refresh
text_2.setAutoDraw(True)
# *mouse_2* updates
if mouse_2.status == NOT_STARTED and t >= 0.0-frameTolerance:
# keep track of start time/frame for later
mouse_2.frameNStart = frameN # exact frame index
mouse_2.tStart = t # local t and not account for scr refresh
mouse_2.tStartRefresh = tThisFlipGlobal # on global time
win.timeOnFlip(mouse_2, 'tStartRefresh') # time at next scr refresh
mouse_2.status = STARTED
mouse_2.mouseClock.reset()
prevButtonState = mouse_2.getPressed() # if button is down already this ISN'T a new click
if mouse_2.status == STARTED: # only update if started and not finished!
buttons = mouse_2.getPressed()
if buttons != prevButtonState: # button state changed?
prevButtonState = buttons
if sum(buttons) > 0: # state changed to a new click
# abort routine on response
continueRoutine = False
# check for quit (typically the Esc key)
if endExpNow or defaultKeyboard.getKeys(keyList=["escape"]):
core.quit()
# check if all components have finished
if not continueRoutine: # a component has requested a forced-end of Routine
break
continueRoutine = False # will revert to True if at least one component still running
for thisComponent in intro_calibatrion_trialComponents:
if hasattr(thisComponent, "status") and thisComponent.status != FINISHED:
continueRoutine = True
break # at least one component has not yet finished
# refresh the screen
if continueRoutine: # don't flip if this routine is over or we'll get a blank screen
win.flip()
# -------Ending Routine "intro_calibatrion_trial"-------
for thisComponent in intro_calibatrion_trialComponents:
if hasattr(thisComponent, "setAutoDraw"):
thisComponent.setAutoDraw(False)
thisExp.addData('text_2.started', text_2.tStartRefresh)
thisExp.addData('text_2.stopped', text_2.tStopRefresh)
# store data for thisExp (ExperimentHandler)
x, y = mouse_2.getPos()
buttons = mouse_2.getPressed()
thisExp.addData('mouse_2.x', x)
thisExp.addData('mouse_2.y', y)
thisExp.addData('mouse_2.leftButton', buttons[0])
thisExp.addData('mouse_2.midButton', buttons[1])
thisExp.addData('mouse_2.rightButton', buttons[2])
thisExp.addData('mouse_2.started', mouse_2.tStart)
thisExp.addData('mouse_2.stopped', mouse_2.tStop)
thisExp.nextEntry()
# the Routine "intro_calibatrion_trial" was not non-slip safe, so reset the non-slip timer
routineTimer.reset()
# Flip one final time so any remaining win.callOnFlip()
# and win.timeOnFlip() tasks get executed before quitting
win.flip()
# these shouldn't be strictly necessary (should auto-save)
thisExp.saveAsWideText(filename+'.csv', delim='auto')
thisExp.saveAsPickle(filename)
logging.flush()
# make sure everything is closed down
thisExp.abort() # or data files will save again on exit
win.close()
core.quit()
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment