0

I'm new to Psychtoolbox and am using it to create a reversing checkerboard pattern on the screen. The checkerboard has been coloured such that it is more like vertical stripes rather than checks. I have two contrasting conditions a regular black/white striped pattern and then a light grey/dark grey striped pattern. I have managed to do everything except I am really struggling with timing.

At first, I was struggling with the timing aspect of things and was not able to get the screen to switch from the grey screen to black and white screen. The waitframes fixed this. However, now that I have each screen appearing for a set duration, the alternation of the pattern has stopped for each texture. Does anybody have advice on how to fix this? What is missing in my code currently that's stopping the reversing of the stripes??

Can anyone provide advice? My code is below.

    % Clear the workspace and the screen
    sca;
    close all;
    clearvars;
    PsychDefaultSetup(2); 
    screens = Screen('Screens');
    screenNumber = max(screens);

    white = WhiteIndex(screenNumber);
    black = BlackIndex(screenNumber);
    grey = white / 2;

    % Open an on screen window
    [window, windowRect] = PsychImaging('OpenWindow', screenNumber, grey, [0 0 400 400]);
    ifi = Screen('GetFlipInterval', window);

    % Query the maximum priority level
    topPriorityLevel = MaxPriority(window);

    [screenXpixels, screenYpixels] = Screen('WindowSize', window);

    %Stripe information Get the centre coordinate of the window
    [xCenter, yCenter] = RectCenter(windowRect);
    cx = (screenXpixels/2);
    cy = (screenYpixels/2);

    % Make a base Rect of 200 by 200 pixels
    dimx = cx;
    dimy = cy;
    baseRect = [0 0 dimx dimy];
    pos = [cx- dimx/2 ,cy - dimy/2,cx+ dimx/2 ,cy + dimy/2];

    [xPos, yPos] = meshgrid(-2:0.5:2, -2:0.5:2);

    % Calculate the number of squares and reshape the matrices of coordinates
    % into a vector
    [s1, s2] = size(xPos);
    numSquares = s1 * s2;
    xPos = reshape(xPos, 1, numSquares);
    yPos = reshape(yPos, 1, numSquares);

    % Set the colors of each of our squares
    %grey colours 
    bwColors = repmat([0.55 0.46; 0.55 0.46], 5, 5);
    bwColors = bwColors(1:end-1, 1:end-1);
    bwColors = reshape(bwColors, 1, numSquares);
    bwColors = repmat(bwColors, 3, 1);

    multiColors = repmat([0.45 0.58; 0.45 0.58], 5, 5);
    multiColors = multiColors(1:end-1, 1:end-1);
    multiColors = reshape( multiColors, 1, numSquares);
    multiColors = repmat( multiColors, 3, 1);

    %black and white colours
    board3 = repmat([1 0; 1 0], 5, 5);
    board3 = board3(1:end-1, 1:end-1);
    board3 = reshape(board3, 1, numSquares);
    board3 = repmat(board3, 3, 1);

    board4 = repmat([0 1; 0 1], 5, 5);
    board4 = board4(1:end-1, 1:end-1);
    board4 = reshape( board4, 1, numSquares);
    board4 = repmat( board4, 3, 1);

    % Texture cue that determines which texture we will show
    textureCue = [1 2];

    % Sync us to the vertical retrace
    vbl = Screen('Flip', window);

    %Timing
    % Time we want to wait before reversing the contrast of the checkerboard
    checkFlipTimeSecs = 0.5;
    checkFlipTimeFrames = round(checkFlipTimeSecs / ifi);
    frameCounter = 0;

    flipSecs = 12;
    waitframes = round(flipSecs / ifi);

    % Keybpard setup
    spaceKey = KbName('space');
    escapeKey = KbName('ESCAPE');
    RestrictKeysForKbCheck([spaceKey escapeKey]);

    %Experimental loop
    % Start screen
    DrawFormattedText(window, 'Press Space To Begin', 'center', 'center', black);
    Screen('Flip', window);
    KbWait;
    numTrials = 10;

    for trial=1:numTrials

        textureCue = [1 2];
        tex(1)= Screen('MakeTexture',window,multiColors);
        tex(2)= Screen('MakeTexture',window,bwColors);
        tex2(1)=Screen('MakeTexture',window,board3);
        tex2(2)=Screen('MakeTexture',window,board4);

        Screen('FillRect', window, grey);
        Screen('Flip', window);

        % This is our drawing loop
        Priority(topPriorityLevel);


    while ~KbCheck
            % Draw the textures or a blank frame
           frameCounter = frameCounter + 1;
             if frameCounter == checkFlipTimeFrames
                textureCue = fliplr(textureCue);
                frameCounter = 0;
             end

     Screen('DrawTexture', window, tex(textureCue(1)), [],pos);
     vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);

            frameCounter = frameCounter + 1;
             if frameCounter == checkFlipTimeFrames
                textureCue = fliplr(textureCue);
                frameCounter = 0;
             end
      Screen('DrawTexture', window, tex2(textureCue(1)), [],pos);
      vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);

   % Poll the keyboard for the space key
    [keyIsDown, secs, keyCode] = KbCheck(-1);
    if keyCode(KbName('space')) == 1
        respMade = 1;

    elseif keyCode(KbName('ESCAPE')) == 1
        sca;
        disp('*** Experiment terminated ***');
        return
    end
    end
    end
       Screen('Close', tex);
       Screen('Close', tex2);
        sca;
Maheen Siddiqui
  • 539
  • 8
  • 19
  • use `pause` and `close` – Sardar Usama Jul 19 '17 at 21:29
  • Could you expand on that? How would I use it? I tried `Screen(close,tex)` before but I kept getting an error on usage of `Screen`. Do you mean after I draw the texture, I say `pause(12)` and then close the screen? – Maheen Siddiqui Jul 19 '17 at 21:31
  • Yes that's what I mean – Sardar Usama Jul 19 '17 at 21:31
  • It didn't work... I only got a blank grey screen, neither of the textures appeared. – Maheen Siddiqui Jul 19 '17 at 21:34
  • @SardarUsama I have cleaned up and minimized the code now... – Maheen Siddiqui Jul 19 '17 at 23:08
  • Can you explain how quickly you would like the textures to alternate? I tried your code and they do alternate, once every 12 seconds. This is because you schedule each texture to begin 12 seconds following the previous texture onset. Do you want them to be on screen for 12 seconds but flicker between the textures every .5 second? – DMR Jul 20 '17 at 18:06

0 Answers0