sca;
close all;
clear;
PsychDefaultSetup(2);
screenNumber = max(Screen('Screens'));
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
grey = white / 2;
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey, [], 32, 2,...
[], [], kPsychNeed32BPCFloat);
ifi = Screen('GetFlipInterval', window);
topPriorityLevel = MaxPriority(window);
Priority(topPriorityLevel);
[xCenter, yCenter] = RectCenter(windowRect);
gaborDimPix = windowRect(4) / 4;
sigma = gaborDimPix / 7;
orientation = 0;
contrast = 0.8;
aspectRatio = 1.0;
phase = 0;
numCycles = 5;
freq = numCycles / gaborDimPix;
backgroundOffset = [0.5 0.5 0.5 0.0];
disableNorm = 1;
preContrastMultiplier = 0.5;
gabortex = CreateProceduralGabor(window, gaborDimPix, gaborDimPix, [],...
backgroundOffset, disableNorm, preContrastMultiplier);
numGabors = 2;
propertiesMat = repmat([phase, freq, sigma, contrast, aspectRatio, 0, 0, 0], numGabors, 1);
propertiesMat(:, 1) = rand(1, 2) * 360;
gabShifts = [0.25 0.75] * windowRect(4);
gaborsRects = nan(4, 2);
for i = 1:numGabors
gaborsRects(:, i) = CenterRectOnPointd([0 0 gaborDimPix gaborDimPix], windowRect(3) / 2, gabShifts(i));
end
vbl = Screen('Flip', window);
waitframes = 1;
phasePerFrame = 4 * pi;
while ~KbCheck
Screen('BlendFunction', window, 'GL_ONE', 'GL_ZERO');
Screen('DrawTextures', window, gabortex, [], gaborsRects, orientation, [], [], [], [],...
kPsychDontDoRotation, propertiesMat');
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
Screen('DrawDots', window, [xCenter; yCenter], 10, black, [], 2);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
propertiesMat(:, 1) = propertiesMat(:, 1) + ([-1; 1] * phasePerFrame);
end
sca;