Psychtoolbox/ Draw four rectangles.
11 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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...!
0 Kommentare
Antworten (1)
Mikel Jimenez
am 20 Jun. 2022
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
0 Kommentare
Siehe auch
Kategorien
Mehr zu Image display and manipulation finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!