Hi, I am using MATLAB R2020a. I am trying to display 3 lines on the screen, all of which vary in angular deviation from the vertical position. I would like to specify this angular deviation based on numbers chosen from a Gaussian distribution. I know there are functions to vary the angle of textures but could not find anything to do this for line stimuli. I would very much appreciate any suggestions. Thanks in advance
Drawlines take the start and end position of a line (x, y). So provide it with a start and end position such that your line has the orientation that you want.
Besides the mentioned Screen(‘Drawline’) or Screen(‘Drawlines’) function, if the line has fixed length, but just rotates, you can also use Screen(‘DrawTexture’) to control the angle without computing the new [x.y]. For this to work, you can create a texture with proper background, and Screen(‘Drawline’, tex) into the texture.
There’s also the Screen(‘glRotate’) subfunction and friends for rotated drawing of stuff, but that needs to be combined with Screen(‘glPushMatrix’ / ‘glPopMatrix’ and ‘glTranslate’) to define the center of rotation and stuff. In principle this is demonstrated in DrawMirroredTextDemo.m, except for scaling the text – by -1 to flip it horizontally. If you’d replace Screen('glScale, …) in line 130 by Screen(‘glRotate’, w, 45); it would rotate the text by 45 degrees. It applies to any drawing command put after the Screen(‘gl…’) commmands and before the Screen(‘glPopMatrix’…) command.
But this just for completeness. It is not very efficient if one wants to rotate many different items individually. The proposals from @dcnieho and @xiangrui are more efficient in this case.
-mario
Hi, thank you for this suggestion. This would be perfect but I am unsure as to how to implement it. Could you please provide sample code? Thanks
Some pseudo code:
% prepare the texture with a line
w = Screen('OpenWindow', ...
tex = Screen('MakeTexture', w, ones(sz)*background);
Screen(‘Drawline’, tex, color, ...); % x, y in tex coordinates
% display the line
Screen(‘DrawTexture’, w, tex, [], [], rotationAngle); % rotationAngle can keep changing
Screen(‘Flip’, w);
Ther’s also DrawingSpeedTest ([], [], 2) to demonstarte this method if one follows the code taken for the ‘2’ setting, or for the ‘3’ setting if one wants the faster batch-drawing of textures mode. One just needs to specify a rotation angle by editing line 172 of that script, so the drawn rectangles are tilted, to get the idea. Optimally one would use Screen(‘OpenOffscreenWindow’) instead of Screen(‘MakeTexture’) as shown in that demo, leave some space at the borders, and maybe also enable alpha-blending as hown there, to get some nice anti-aliasing of the tilted lines.
-mario