这个简短的程序应该显示绿色的全屏背景和
中心有一个400 x 400像素的红色正方形。但是,红色方块位于顶部左侧角[0, 0, 400, 400]
而不是居中。
try
screens = Screen('Screens'); % check for number of screens (currently '0' because only one screen is connected)
whichscreen = max(screens);
[myscreen,rect]=Screen('OpenWindow', whichscreen, [0, 255,0]);
screen_rect = [0, 0, 1366, 768];
square_size = [0, 0, 400, 400];
square_rect = CenterRect(square_size, screen_rect);
Screen('FillRect', myscreen, [255, 0, 0], square_size);
Screen('Flip', myscreen);
KbWait;
Screen('CloseAll');
catch
Screen('CloseAll');
end
此外,按下键盘上的按钮时程序不会关闭。
知道问题是什么吗?
谢谢&最好, Ĵ
答案 0 :(得分:1)
您使用的是错误的变量。您正在绘制一个矩形到square_size
而不是square_rect
- 因此很明显矩形被绘制到[0, 0, 400, 400]
。
try
screens = Screen('Screens'); % check for number of screens (currently '0' because only one screen is connected)
whichscreen = max(screens); %
[myscreen,rect]=Screen('OpenWindow', whichscreen, [0, 255,0]);
screen_rect = [0, 0, 1366, 768];
square_size = [0, 0, 400, 400];
square_rect = CenterRect(square_size, screen_rect);
Screen('FillRect', myscreen, [255, 0, 0], square_rect);
Screen('Flip', myscreen);
KbWait;
Screen('CloseAll');
catch
Screen('CloseAll');
end
此外,您可以使用rect
提供的Screen('OpenWindow')
变量,将其缩短并兼容您使用的每台显示器。
try
screens = Screen('Screens');
whichscreen = max(screens);
[myscreen,rect]=Screen('OpenWindow', whichscreen, [0, 255,0]);
square_size = [0, 0, 400, 400];
square_position = CenterRect(square_size, rect);
Screen('FillRect', myscreen, [255, 0, 0], square_position);
Screen('Flip', myscreen);
KbWait;
Screen('CloseAll');
catch
Screen('CloseAll');
end