Psychtoolbox/ Draw four rectangles.

조회 수: 9 (최근 30일)
MuYeoung Jeung
MuYeoung Jeung 2018년 1월 30일
답변: Mikel Jimenez 2022년 6월 20일
PsychDefaultSetup(2);
+Screen('Preference', 'SkipSyncTests', 1);
+
+screens = Screen('Screens');
+screenNumber = max(screens);
+
+white = WhiteIndex(screenNumber);
+black = BlackIndex(screenNumber);
+
+[wPtr, rect] = PsychImaging('OpenWindow', screenNumber, black);
+
+[screenXpixels, screenYpixels] = Screen('WindowSize', wPtr);
+[xCenter, yCenter] = RectCenter(rect);
+
+baseRect = [0 0 100 100];
+
+squareXpos = [screenXpixels * 0.15 screenXpixels * 0.25 screenXpixels * 0.35 screenXpixels * 0.45];
+squareYpos = [screenYpixels * 0.15 screenYpixels * 0.25 screenYpixels * 0.35 screenYpixels * 0.45];
+numSquares = length(squareXpos);
+
+allColors = [1 0 0; 0 1 0; 0 0 1; 1 0 0];
+
+
+allRects = nan(4, 4);
+for i = 1:numSquares
+ allRects(:, i) = CenterRectOnPointd(baseRect, squareXpos(i), squareYpos(i));
+
+end
+
+Screen('FillRect', wPtr, allColors, allRects);
+Screen('Flip', wPtr);
+
+KbWait;
+sca;
I'd like to draw four rectangles. But there is a error like "Screen('FillRect', windowPtr [,color] [,rect] )" . I don't know why this code has a error... Please, help me...!

답변 (1개)

Mikel Jimenez
Mikel Jimenez 2022년 6월 20일
Hi,
I think you need to provide allColors and allRects as column vectors:
"Instead of filling one rectangle, you can also specify a list of multiple rectangles to be filled - this is much faster when you need to draw many rectangles per frame. To fill n rectangles, provide “rect” as a 4 rows by n columns matrix, each column specifying one rectangle, e.g., rect(1,5)=left border of 5th rectange, rect(2,5)=top border of 5th rectangle, rect(3,5)=right border of 5th rectangle, rect(4,5)=bottom border of 5th rectangle. If the rectangles should have different colors, then provide “color” as a 3 or 4 row by n column matrix, the i’th column specifiying the color of the i’th rectangle."
Not sure if you are doing it this way, yet I guess you have sorted this out by now.
Best,
Mikel

카테고리

Help CenterFile Exchange에서 Image display and manipulation에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!