close all;
clear;
commandwindow;
PsychDefaultSetup(2);
rng('shuffle')
Screen('Preference', 'SkipSyncTests', 2);
screenNumber = max(Screen('Screens'));
white = WhiteIndex(screenNumber);
grey = white / 2;
black = BlackIndex(screenNumber);
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey, [], 32, 2);
Screen('Flip', window);
ifi = Screen('GetFlipInterval', window);
Screen('TextSize', window, 60);
topPriorityLevel = MaxPriority(window);
[xCenter, yCenter] = RectCenter(windowRect);
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
isiTimeSecs = 1;
isiTimeFrames = round(isiTimeSecs / ifi);
waitframes = 1;
imageSecs = 1;
imageFrames = round(imageSecs / ifi);
blankSecs = 0.25;
blankFrames = round(blankSecs / ifi);
presVector = [ones(1, imageFrames) zeros(1, blankFrames)...
ones(1, imageFrames) .* 2 zeros(1, blankFrames)];
numPresLoopFrames = length(presVector);
spaceKey = KbName('space');
escapeKey = KbName('ESCAPE');
RestrictKeysForKbCheck([spaceKey escapeKey]);
imageFolder = [cd '/images/'];
imgList = dir(fullfile(imageFolder, '*.jpg'));
imgList = {imgList(:).name};
numImages = length(imgList);
isOdd = mod(numImages, 2);
if isOdd == 1
error('*** Number of files has to be even to procede ***');
end
numTrials = numImages / 2;
trialType = [1 2];
numExamples = 2;
trialLine = repmat(trialType, 1, numExamples);
exampleLine = sort(repmat(1:numExamples, 1, 2));
condMat = [trialLine; exampleLine];
shuffler = Shuffle(1:numTrials);
condMatShuff = condMat(:, shuffler);
resultsMatrix = nan(numTrials, 3);
resultsMatrix(:, 1:2) = condMatShuff';
resultsDir = [cd '/Results/'];
if exist(resultsDir, 'dir') < 1
mkdir(resultsDir);
end
crossFrac = 0.0167;
fixCrossDimPix = windowRect(4) * crossFrac;
xCoords = [-fixCrossDimPix fixCrossDimPix 0 0];
yCoords = [0 0 -fixCrossDimPix fixCrossDimPix];
allCoords = [xCoords; yCoords];
lineWidthPix = 4;
DrawFormattedText(window, 'Press Space To Begin', 'center', 'center', black);
Screen('Flip', window);
KbWait;
for trial = 1:numTrials
thisTrialType = condMatShuff(1, trial);
thisExample = condMatShuff(2, trial);
if thisTrialType == 1
trialTypeLabel = 'colorchange';
elseif thisTrialType == 2
trialTypeLabel = 'disappearance';
end
imageNameA = ['image' num2str(thisExample) '_' trialTypeLabel 'A.jpg'];
imageNameB = ['image' num2str(thisExample) '_' trialTypeLabel 'B.jpg'];
theImageA = imread([imageFolder imageNameA]);
theImageB = imread([imageFolder imageNameB]);
texA = Screen('MakeTexture', window, theImageA);
texB = Screen('MakeTexture', window, theImageB);
Screen('FillRect', window, grey);
Screen('DrawLines', window, allCoords,...
lineWidthPix, white, [xCenter yCenter], 2);
Screen('Flip', window);
WaitSecs(2);
respMade = 0;
numFrames = 0;
frame = 0;
Priority(topPriorityLevel);
while respMade == 0
numFrames = numFrames + 1;
frame = frame + 1;
if frame > numPresLoopFrames
frame = 1;
end
showWhat = presVector(frame);
if showWhat == 1
Screen('DrawTexture', window, texA, [], [], 0);
elseif showWhat == 2
Screen('DrawTexture', window, texB, [], [], 0);
elseif showWhat == 0
Screen('FillRect', window, grey);
end
if numFrames == 1
vbl = Screen('Flip', window);
else
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
end
[keyIsDown, secs, keyCode] = KbCheck(-1);
if keyCode(KbName('space')) == 1
respMade = 1;
elseif keyCode(KbName('ESCAPE')) == 1
sca;
disp('*** Experiment terminated ***');
return
end
end
timeTakenSecs = numFrames * ifi;
Priority(0);
Screen('Close', texA);
Screen('Close', texB);
resultsMatrix(trial, 3) = timeTakenSecs;
end
sca
return