sca;
close all;
clear;
PsychDefaultSetup(2);
screens = Screen('Screens');
screenNumber = max(screens);
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, black);
Screen('BlendFunction', window, GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
ifi = Screen('GetFlipInterval', window);
[xCenter, yCenter] = RectCenter(windowRect);
baseRect = [0 0 200 200];
topColor = [1 0 0];
bottomColor = [0 0 1];
amplitude = screenXpixels * 0.25;
frequency = 0.2;
angFreq = 2 * pi * frequency;
time = 0;
startPhaseOne = 0;
startPhaseTwo = pi;
vbl = Screen('Flip', window);
waitframes = 1;
topPriorityLevel = MaxPriority(window);
Priority(topPriorityLevel);
while ~KbCheck
xposOne = amplitude * sin(angFreq * time + startPhaseOne);
xposTwo = amplitude * sin(angFreq * time + startPhaseTwo);
squareXposOne = xCenter + xposOne;
squareXposTwo = xCenter + xposTwo;
centeredRectOne = CenterRectOnPointd(baseRect, squareXposOne,...
screenYpixels * 0.25);
centeredRectTwo = CenterRectOnPointd(baseRect, squareXposTwo,...
screenYpixels * 0.75);
Screen('FillRect', window, [topColor' bottomColor'],...
[centeredRectOne' centeredRectTwo']);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
time = time + ifi;
end
sca;