# Avoiding overlap of images on the screen

**URL:** <https://psychtoolbox.discourse.group/t/avoiding-overlap-of-images-on-the-screen/1872>\
**Category:** Uncategorized\
**Created:** [March 20, 2008, 2:35pm UTC](https://psychtoolbox.discourse.group/t/avoiding-overlap-of-images-on-the-screen/1872 "2008-03-20T14:35:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![setugh](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@setugh](https://psychtoolbox.discourse.group/u/setugh)\
**Post date:** [March 20, 2008, 2:35pm UTC](https://psychtoolbox.discourse.group/t/avoiding-overlap-of-images-on-the-screen/1872/1 "2008-03-20T14:35:15Z")

</div>

Hi,  
  
I am designing an experiment in which I present a few items on the   
screen for some amount of time and I add few more items while the   
previous items continue to be on the screen.  
  
I have not been able to avoid the overlap of these images. Could you   
suggest a way to avoid already occupied locations?  
  
Thanks in advance.  
  
Setu

---

<div class="post-metadata">

**Author:** ![konaketa](https://avatars.discourse-cdn.com/v4/letter/k/c37758/32.png) [@konaketa](https://psychtoolbox.discourse.group/u/konaketa)\
**Post date:** [March 20, 2008, 9:58pm UTC](https://psychtoolbox.discourse.group/t/avoiding-overlap-of-images-on-the-screen/1872/2 "2008-03-20T21:58:06Z")

</div>

Couple of quick questions:  
what are your items? textures(.jpgs) , drawings, text?  
are they of uniform or different sizes?  
are they always in the same locations?  
  
I know that when I have to display an array of images (jpgs-\>textures),  
I divide my total display area into a grid of equal sized blocks-- a  
800x600 would be 4(four) 400x300 mini blocks, with centers at 200,150;  
600,150; 200, 450; and 600,450 respectively if you had them arranged  
like:  
  
A B  
C D  
  
just specify the coordinates at the beginning of your script in some  
meaningful manner so you can reference them appropriately for the  
destrect(s) that you specify when you make your textures . You also  
might want to specify your image size(s) (obviously to some size less  
than your destrect so there is separation ;-)  
  
I know that it helps me to sit down and do what I did when I was on the  
yearbook (all those aeons ago): grab some graph paper and block out your  
screen layout as if it were a page. That way you muck around with  
pencil and eraser to get the layout right before you muddy your code.  
  
Allisson  
  
  
  
  
  
%%% This is my ugly code for my first experiment, where I had side by  
side stimuli and a center only stimuli  
  
Screen('Screens');  
Screen('Preference','SkipSyncTests',0);% set to 0 for experiments!!!!  
HideCursor;  
 ysize=350; %image size in pixels y-dim  
 xsize=350; %image size in pixels x-dim  
 ysize2=ysize; % this is if I need to have different sizes  
 xsize2=xsize;  
 x=0; % drawing position relative to center  
 y=0;  
 ang = 0; % rotation angle (degrees)  
  
[w,rect]=Screen('OpenWindow',0, [25 25 50]);  
Screen('TextSize', w ,14);  
Screen('FillRect', w, [25 25 50]);  
 Screen('Flip', w);  
 priorityLevel = MaxPriority(w);  
 Priority(priorityLevel);  
  
 x0 = rect(3)/2; % screen center  
 y0 = rect(4)/2;  
 x3 = rect(3)/3; % 1/3 of screen  
 x4 = x3\*2; %2/3 of screen  
 s1=.5; %this scales the stimuli to half size  
 s2=1;  
 destrectL = [x3-s1\*xsize2+x, y0-s1\*ysize2+y, x3+s1\*xsize2+x, ...  
 y0+s1\*ysize2+y]; % left position  
 destrectR = [x4-s1\*xsize2+x, y0-s1\*ysize2+y, x4+s1\*xsize2+x, ...  
 y0+s1\*ysize2+y]; %right position  
 destrect = [x0-s2\*xsize/2+x, y0-s2\*ysize/2+y, x0+s2\*xsize/2+x, ...  
 y0+s2\*ysize/2+y]; %center position  
  
  
%%%% end ugly code  
  
  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "setugh" \<setugh@...\> wrote:  
> \>  
> \> Hi,  
> \>  
> \> I am designing an experiment in which I present a few items on the  
> \> screen for some amount of time and I add few more items while the  
> \> previous items continue to be on the screen.  
> \>  
> \> I have not been able to avoid the overlap of these images. Could you  
> \> suggest a way to avoid already occupied locations?  
> \>  
> \> Thanks in advance.  
> \>  
> \> Setu  
> \>

---

<div class="post-metadata">

**Author:** ![setugh](https://avatars.discourse-cdn.com/v4/letter/s/ed8c4c/32.png) [@setugh](https://psychtoolbox.discourse.group/u/setugh)\
**Post date:** [March 20, 2008, 10:41pm UTC](https://psychtoolbox.discourse.group/t/avoiding-overlap-of-images-on-the-screen/1872/3 "2008-03-20T22:41:58Z")

</div>

Hi,  
  
The items are bitmap images and they are of uniform size. And they are not in the same   
locations across trials. But as I mentioned earlier I present few items on the screen and   
they'll remain either in the same place or change their places a little bit (this is actually a   
condition in my expt. change location and no change) when I add the new items.  
  
For example, the first set of items is presented for 500ms and then new items are added.  
The problem is I have hard-coded the locations for the first set of items because they   
need to be in a particular configuration. But the other set needs to randomly distributed   
over the screen (thus avoiding overlap with already present items).  
  
Hope I have made my problem clear!   
  
Thanks,  
Setu  
  
  
  
  
  
  
  

> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "konaketa" \<hseiler@...\> wrote:  
> \>  
> \>   
> \> Couple of quick questions:  
> \> what are your items? textures(.jpgs) , drawings, text?  
> \> are they of uniform or different sizes?  
> \> are they always in the same locations?  
> \>   
> \> I know that when I have to display an array of images (jpgs-\>textures),  
> \> I divide my total display area into a grid of equal sized blocks-- a  
> \> 800x600 would be 4(four) 400x300 mini blocks, with centers at 200,150;  
> \> 600,150; 200, 450; and 600,450 respectively if you had them arranged  
> \> like:  
> \>   
> \> A B  
> \> C D  
> \>   
> \> just specify the coordinates at the beginning of your script in some  
> \> meaningful manner so you can reference them appropriately for the  
> \> destrect(s) that you specify when you make your textures . You also  
> \> might want to specify your image size(s) (obviously to some size less  
> \> than your destrect so there is separation ;-)  
> \>   
> \> I know that it helps me to sit down and do what I did when I was on the  
> \> yearbook (all those aeons ago): grab some graph paper and block out your  
> \> screen layout as if it were a page. That way you muck around with  
> \> pencil and eraser to get the layout right before you muddy your code.  
> \>   
> \> Allisson  
> \>   
> \>   
> \>   
> \>   
> \>   
> \> %%% This is my ugly code for my first experiment, where I had side by  
> \> side stimuli and a center only stimuli  
> \>   
> \> Screen('Screens');  
> \> Screen('Preference','SkipSyncTests',0);% set to 0 for experiments!!!!  
> \> HideCursor;  
> \> ysize=350; %image size in pixels y-dim  
> \> xsize=350; %image size in pixels x-dim  
> \> ysize2=ysize; % this is if I need to have different sizes  
> \> xsize2=xsize;  
> \> x=0; % drawing position relative to center  
> \> y=0;  
> \> ang = 0; % rotation angle (degrees)  
> \>   
> \> [w,rect]=Screen('OpenWindow',0, [25 25 50]);  
> \> Screen('TextSize', w ,14);  
> \> Screen('FillRect', w, [25 25 50]);  
> \> Screen('Flip', w);  
> \> priorityLevel = MaxPriority(w);  
> \> Priority(priorityLevel);  
> \>   
> \> x0 = rect(3)/2; % screen center  
> \> y0 = rect(4)/2;  
> \> x3 = rect(3)/3; % 1/3 of screen  
> \> x4 = x3\*2; %2/3 of screen  
> \> s1=.5; %this scales the stimuli to half size  
> \> s2=1;  
> \> destrectL = [x3-s1\*xsize2+x, y0-s1\*ysize2+y, x3+s1\*xsize2+x, ...  
> \> y0+s1\*ysize2+y]; % left position  
> \> destrectR = [x4-s1\*xsize2+x, y0-s1\*ysize2+y, x4+s1\*xsize2+x, ...  
> \> y0+s1\*ysize2+y]; %right position  
> \> destrect = [x0-s2\*xsize/2+x, y0-s2\*ysize/2+y, x0+s2\*xsize/2+x, ...  
> \> y0+s2\*ysize/2+y]; %center position  
> \>   
> \>   
> \> %%%% end ugly code  
> \>   
> \>   
> \>   
> \> --- In [psychtoolbox@yahoogroups.com](mailto:psychtoolbox@yahoogroups.com), "setugh" \<setugh@\> wrote:  
> \> \>  
> \> \> Hi,  
> \> \>  
> \> \> I am designing an experiment in which I present a few items on the  
> \> \> screen for some amount of time and I add few more items while the  
> \> \> previous items continue to be on the screen.  
> \> \>  
> \> \> I have not been able to avoid the overlap of these images. Could you  
> \> \> suggest a way to avoid already occupied locations?  
> \> \>  
> \> \> Thanks in advance.  
> \> \>  
> \> \> Setu  
> \> \>  
> \>
