# Drawing tilted rectangles with different angles

**URL:** <https://psychtoolbox.discourse.group/t/drawing-tilted-rectangles-with-different-angles/316>\
**Category:** Uncategorized\
**Created:** [June 7, 2013, 8:46pm UTC](https://psychtoolbox.discourse.group/t/drawing-tilted-rectangles-with-different-angles/316 "2013-06-07T20:46:56Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![finallyfree\_fg](https://avatars.discourse-cdn.com/v4/letter/f/e274bd/32.png) [@finallyfree\_fg](https://psychtoolbox.discourse.group/u/finallyfree_fg)\
**Post date:** [June 7, 2013, 8:46pm UTC](https://psychtoolbox.discourse.group/t/drawing-tilted-rectangles-with-different-angles/316/1 "2013-06-07T20:46:56Z")

</div>

Hi all,  
  
I'm drawing 4 rectangles with randomized rotations. They seem randomized in terms of their angels, however I need each one to be a little bit different than others. The rotated angle of the rectangles should not be close to each other, they all should be at least 10 degrees apart. And this also should be randomized. How can I define this? Thank you!  
  
This is how I draw the rectangles:   
  
rot\_angle1=randi(360);   
rot\_angle2=randi(360);   
rot\_angle3=randi(360);   
rot\_angle4=randi(360);   
  
rect\_array=255\*ones(1,1);  
t1=Screen('MakeTexture',w,rect\_array);  
t2=Screen('MakeTexture',w,rect\_array);  
t3=Screen('MakeTexture',w,rect\_array);  
t4=Screen('MakeTexture',w,rect\_array);  
t5=Screen('MakeTexture',w,rect\_array);  
  
destrect(1,:) = (ul\_c + stim\_array);  
destrect(2,:) = (ur\_c + stim\_array);  
destrect(3,:) = (ll\_c + stim\_array);  
destrect(4,:) = (lr\_c + stim\_array);  
  
Screen('DrawTexture',w,t2,[],destrect(1,:),rot\_angle1);  
Screen('DrawTexture',w,t3,[],destrect(2,:),rot\_angle2);  
Screen('DrawTexture',w,t4,[],destrect(3,:),rot\_angle3);  
Screen('DrawTexture',w,t5,[],destrect(4,:),rot\_angle4);  
Screen('Flip',w);

---

<div class="post-metadata">

**Author:** ![gennaer](https://avatars.discourse-cdn.com/v4/letter/g/6a8cbe/32.png) [@gennaer](https://psychtoolbox.discourse.group/u/gennaer)\
**Post date:** [June 7, 2013, 10:20pm UTC](https://psychtoolbox.discourse.group/t/drawing-tilted-rectangles-with-different-angles/316/2 "2013-06-07T22:20:50Z")

</div>

Take a look at DrawTextures. You can draw multiple rectangles at once and there's a parameter that lets you specify a rotation angle. You don't need to make a separate texture for each rectangle.   
  
Genna  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "gozenmanf" \<filizg@...\> wrote:  
> \>  
> \> Hi all,  
> \>   
> \> I'm drawing 4 rectangles with randomized rotations. They seem randomized in terms of their angels, however I need each one to be a little bit different than others. The rotated angle of the rectangles should not be close to each other, they all should be at least 10 degrees apart. And this also should be randomized. How can I define this? Thank you!  
> \>   
> \> This is how I draw the rectangles:   
> \>   
> \> rot\_angle1=randi(360);   
> \> rot\_angle2=randi(360);   
> \> rot\_angle3=randi(360);   
> \> rot\_angle4=randi(360);   
> \>   
> \> rect\_array=255\*ones(1,1);  
> \> t1=Screen('MakeTexture',w,rect\_array);  
> \> t2=Screen('MakeTexture',w,rect\_array);  
> \> t3=Screen('MakeTexture',w,rect\_array);  
> \> t4=Screen('MakeTexture',w,rect\_array);  
> \> t5=Screen('MakeTexture',w,rect\_array);  
> \>   
> \> destrect(1,:) = (ul\_c + stim\_array);  
> \> destrect(2,:) = (ur\_c + stim\_array);  
> \> destrect(3,:) = (ll\_c + stim\_array);  
> \> destrect(4,:) = (lr\_c + stim\_array);  
> \>   
> \> Screen('DrawTexture',w,t2,[],destrect(1,:),rot\_angle1);  
> \> Screen('DrawTexture',w,t3,[],destrect(2,:),rot\_angle2);  
> \> Screen('DrawTexture',w,t4,[],destrect(3,:),rot\_angle3);  
> \> Screen('DrawTexture',w,t5,[],destrect(4,:),rot\_angle4);  
> \> Screen('Flip',w);  
> \>
