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];
rectColor = [0 0 1];
amplitude = screenXpixels * 0.25;
frequency = 0.2;
angFreq = 2 * pi * frequency;
startPhase = 0;
time = 0;
vbl = Screen('Flip', window);
waitframes = 1;
topPriorityLevel = MaxPriority(window);
Priority(topPriorityLevel);
while ~KbCheck
xpos = amplitude * sin(angFreq * time + startPhase);
squareXpos = xCenter + xpos;
centeredRect = CenterRectOnPointd(baseRect, squareXpos, yCenter);
Screen('FillRect', window, rectColor, centeredRect);
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
time = time + ifi;
end
sca;