Centering a rectangle using FillRect

조회 수: 7 (최근 30일)
Steve
Steve 2014년 10월 10일
댓글: Image Analyst 2014년 10월 11일
I need to center the rectangle drawn but it is in the top left corner. Where do I put the coordinates to make the rectangle in the center?
% Displays a horizontal or vertical bar at random and asks for the
% orientation of the bar
% Color variables
blackCol = [127 127 127]; % background screen
greenCol = [0 300 0];
whiteCol = [500 500 500];
screenPixWidth = 1280; %Screen Dimensions
screenPixHeight = 1024;
monitorHeight = 19.5; % inches
monitorWidth = 14.3;
visualAngle= 1; %desired visual angle
distance= 24; %distance from the screen subject is in inches
% solve for height of the rectangle given the visual angle and dist. from
% screen
theta= (visualAngle/180)*pi;
h = 2*distance*tan(theta/2);
heightppi = screenPixHeight/monitorHeight; %calculate ppi
widthppi = screenPixWidth/monitorWidth;
rectangleHeight = heightppi*h;
rectangleWidth = widthppi * (h/2);
height = ceil(rectangleHeight);
width = ceil(rectangleWidth);
recta = [0 0 width height];
whichScreen = 0;
window = Screen(whichScreen, 'OpenWindow', blackCol);
Screen('FillRect', window, greenCol, recta);
Screen('Flip',window,0,0);
WaitSecs(1);
Screen('CloseAll');
  댓글 수: 3
Steve
Steve 2014년 10월 10일
편집: Image Analyst 2014년 10월 11일
I am using psychtoolbox and sorry for the bad format I will use it next time. I am new to all of this.
Image Analyst
Image Analyst 2014년 10월 11일
OK Steve, I thought I'd fix it for you this time, so I formatted your code for you. I also found out that psychtoolbox is not a MATLAB product but a third party product, and I put a link for it in in your message. No one else who posted any questions on it put links to it either, that I could find after looking at a bunch so I tracked it down myself and put it in there in case anyone else wants to check it out. Basically you can put an angle bracket, then the URL, then some words you want the link to say, then a closing angle bracket, like < URL bluewords text > and that will create the link.

댓글을 달려면 로그인하십시오.

답변 (1개)

SK
SK 2014년 10월 10일
편집: SK 2014년 10월 10일
You know the screen pixel dimensions. Using this change recta appropriately - its a simple calculation. Right now you have the top-left of recta set to 0,0.
By the way Screen() does not come with any official Matlab product. Are you aware that you are using psychtoolbox, a third party library?

카테고리

Help CenterFile Exchange에서 Timing and presenting 2D and 3D stimuli에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by