sca;
close all;
clear;
PsychDefaultSetup(2);
screens = Screen('Screens');
screenNumber = max(screens);
white = WhiteIndex(screenNumber);
black = BlackIndex(screenNumber);
grey = GrayIndex(screenNumber);
darkGrey = white * 0.25;
[window, windowRect] = PsychImaging('OpenWindow', screenNumber, darkGrey);
[screenXpixels, screenYpixels] = Screen('WindowSize', window);
ifi = Screen('GetFlipInterval', window);
Screen('BlendFunction', window, 'GL_SRC_ALPHA', 'GL_ONE_MINUS_SRC_ALPHA');
[xCenter, yCenter] = RectCenter(windowRect);
morterWidth = 3;
dim = 5;
gridSqSize = screenYpixels * 0.3 / (dim - 1);
[xposOrig, yposOrig] = meshgrid(-dim:dim, -dim:dim);
xpos = xposOrig .* gridSqSize + xCenter;
ypos = yposOrig .* gridSqSize + yCenter;
grid = repmat(reshape(mod(xposOrig + yposOrig, 2), 1, numel(xposOrig)), 3, 1);
[s1, s2] = size(ypos);
numSquares = numel(ypos);
allRectsSquares = nan(numSquares, 4);
allRectsMortar = nan(numSquares, 4);
ticker = 0;
for i = 1:s1
if mod(i, 2) == 1
adder = gridSqSize / 2;
else
adder = 0;
end
for ii = 1:s2
ticker = ticker + 1;
allRectsSquares(ticker, :) = CenterRectOnPointd([0 0 gridSqSize gridSqSize],...
xpos(i, ii) + adder, ypos(i, ii));
if i == 1 || ii == 1 || i == s1 || ii == s2
allRectsMortar(ticker, :) = CenterRectOnPointd([0 0 gridSqSize + morterWidth gridSqSize + morterWidth],...
xpos(i, ii) + adder, ypos(i, ii));
end
end
end
allRectsMortar = allRectsMortar(all(~isnan(allRectsMortar), 2), :);
Screen('FillRect', window, grey, allRectsMortar');
Screen('FillRect', window, grid, allRectsSquares');
Screen('FrameRect', window, grey, allRectsSquares', morterWidth);
Screen('Flip', window);
KbStrokeWait(-1);
sca;