Centering a rectangle using FillRect
6 次查看(过去 30 天)
显示 更早的评论
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 个评论
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
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?
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!