Moving Oval in Circle using Psychtoolbox in Matlab
조회 수: 7 (최근 30일)
이전 댓글 표시
Hi.
I have succeeded moving oval diagonally using Psychtoolbox in Matlab.
Here is the code for this.
% Clear the workspace close all; clear all; sca;
% Here we call some default settings for setting up Psychtoolbox PsychDefaultSetup(2);
% Get the screen numbers screens = Screen('Screens'); Screen('Preference', 'VisualDebugLevel', 1);
% Draw to the external screen if avaliable screenNumber = max(screens);
% Define black and white white = WhiteIndex(screenNumber); black = BlackIndex(screenNumber);
% Open an on screen window [window, windowRect] = PsychImaging('OpenWindow', screenNumber, black);
% Get the size of the on screen window [screenXpixels, screenYpixels] = Screen('WindowSize', window);
% Query the frame duration ifi = Screen('GetFlipInterval', window);
% Get the centre coordinate of the window [xCenter, yCenter] = RectCenter(windowRect);
% Make a base Rect of 20 by 20 pixels baseRect = [0 0 20 20]; maxDiameter = max(baseRect) * 1.00;
% Set the color of the rect to red rectColor = [1 0 0];
% Our square will oscilate with a sine wave function to the left and right % of the screen. These are the parameters for the sine wave % See: http://en.wikipedia.org/wiki/Sine_wave amplitude = screenXpixels * 0.25; frequency = 1; angFreq = 2 * pi * frequency; startPhase = 0; time = 0;
% Sync us and get a time stamp vbl = Screen('Flip', window); waitframes = 1;
% Maximum priority level topPriorityLevel = MaxPriority(window); Priority(topPriorityLevel);
% Loop the animation until a key is pressed
while ~KbCheck
% Position of the square on this frame
xpos = amplitude*1.875 * cos(angFreq * time + startPhase);
ypos = amplitude*1 * cos(angFreq * time + startPhase);
% Add this position to the screen center coordinate. This is the point
% we want our square to oscillate around
squareXpos = xCenter - xpos;
squareYpos = yCenter + ypos;
% Center the rectangle on the centre of the screen
centeredRect = CenterRectOnPointd(baseRect, squareXpos, squareYpos);
% Draw the rect to the screen
Screen('FillOval', window, rectColor, centeredRect, maxDiameter);
% Flip to the screen
vbl = Screen('Flip', window, vbl + (waitframes - 0.5) * ifi);
% Increment the time
time = time + ifi;
end
% Clear the screen sca; close all; clear all;
From this code, I need to move oval in circle (either clockwise or anticlockwise). Can you please indicate which code to change from this Code Demo.
Further, the reason why I am using these experimental designs (moving oval in circle or diagonal) is to apply it into Eye-tracking (instead of using the Experimental Builder software).
How can I automatically save the Eye Link data while showing this Psychtoolbox stimulus on the computer screen.
Thank You.
댓글 수: 0
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Image display and manipulation에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!