如何设置纹理在Psychtoolbox中出现的持续时间?

时间:2017-07-19 21:04:03

标签: matlab time timer textures psychtoolbox

我是Psychtoolbox的新手,并且正在使用它在屏幕上创建一个倒车棋盘图案。棋盘已经着色,使其更像是垂直条纹而不是支票。我有两个对比条件,一个普通的黑色/白色条纹图案,然后是浅灰色/深灰色条纹图案。我已经设法做了所有事情,除了我真的在时间上苦苦挣扎。

起初,我正在努力解决时间问题,并且无法让屏幕从灰色屏幕切换到黑白屏幕。等待帧修复了这一点。但是,现在我让每个屏幕出现一段设定的持续时间,每个纹理的模式交替停止。有没有人就如何解决这个问题提出建议?我的代码目前缺少什么来阻止条纹的反转?

有人可以提供建议吗?我的代码如下。

    % 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;

0 个答案:

没有答案