# Mutliple stimulus with 1 screen

**URL:** <https://psychtoolbox.discourse.group/t/mutliple-stimulus-with-1-screen/1238>\
**Category:** Uncategorized\
**Created:** [September 25, 2016, 3:10am UTC](https://psychtoolbox.discourse.group/t/mutliple-stimulus-with-1-screen/1238 "2016-09-25T03:10:32Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Allen\_Ingling](https://avatars.discourse-cdn.com/v4/letter/a/a183cd/32.png) [@Allen\_Ingling](https://psychtoolbox.discourse.group/u/Allen_Ingling)\
**Post date:** [September 25, 2016, 3:10am UTC](https://psychtoolbox.discourse.group/t/mutliple-stimulus-with-1-screen/1238/1 "2016-09-25T03:10:32Z")

</div>

Hello Everyone,  
  
I am new to using Psychtoolbox and haven't figured out a lot. I figured out how to make a moving dots stimulus with a single set of dots, but what I would like to do is have 2 sets moving in separate directions. I.e. red dot set moving left, green dot set moving diagonal, etc., I can figure out how to generate the second set of dots, but I'm not sure how to get the Screen function to display both simultaneously. Could someone please help and let me know how to append it to my code.  
I am on Windows 10  
And here is the section of code I am using to generate my display screen:  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goodDots = (dots.x-dots.center(1)).^2/(dots.apertureSize(1)/2)^2 + ...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (dots.y-dots.center(2)).^2/(dots.apertureSize(2)/2)^2 \< 1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; goodDots2 = (dots.x2-dots.center2(1)).^2/(dots.apertureSize2(1)/2)^2 + ...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; (dots.y-dots.center2(2)).^2/(dots.apertureSize2(2)/2)^2 \< 1;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %convert from degrees to screen pixels  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixpos.x = angle2pix(display,dots.x)+ display.resolution(1)/2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixpos.y = angle2pix(display,dots.y)+ display.resolution(2)/2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixpos.x2 = angle2pix(display,dots.x)+ display.resolution(1)/2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; pixpos.y2 = angle2pix(display,dots.y)+ display.resolution(2)/2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Screen('DrawDots',display.windowPtr,[pixpos.x;pixpos.y], dots.size, dots.color,[0,0],1);  
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; %^-- displays the first set of dots, but need the 2nd group (pixpos.x2, pixpos.y2) displayed &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; simultaneously  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %update the dot position  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.x = dots.x + dx;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.y = dots.y + dy;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.x2 = dots.x2 + dx2;  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.y2 = dots.y2 + dy2;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %move the dots that are outside the aperture back one aperture  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %width.  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.x(dots.x\<l) = dots.x(dots.x\<l) + dots.apertureSize(1);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.x(dots.x\>r) = dots.x(dots.x\>r) - dots.apertureSize(1);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.y(dots.y\<b) = dots.y(dots.y\<b) + dots.apertureSize(2);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.y(dots.y\>t) = dots.y(dots.y\>t) - dots.apertureSize(2);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.x2(dots.x\<l) = dots.x2(dots.x\<l) + dots.apertureSize2(1);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.x2(dots.x\>r) = dots.x2(dots.x\>r) - dots.apertureSize2(1);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.y2(dots.y\<b) = dots.y2(dots.y\<b) + dots.apertureSize2(2);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.y2(dots.y\>t) = dots.y2(dots.y\>t) - dots.apertureSize2(2);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %increment the 'life' of each dot  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.life = dots.life+1;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %find the 'dead' dots  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; deadDots = mod(dots.life,dots.lifetime)==0;  
  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; %replace the positions of the dead dots to a random location  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.x(deadDots) = (rand(1,sum(deadDots))-.5)\*dots.apertureSize(1) + dots.center(1);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.y(deadDots) = (rand(1,sum(deadDots))-.5)\*dots.apertureSize(2) + dots.center(2);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.x2(deadDots) = (rand(1,sum(deadDots))-.5)\*dots.apertureSize2(1) + dots.center2(1);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; dots.y2(deadDots) = (rand(1,sum(deadDots))-.5)\*dots.apertureSize2(2) + dots.center2(2);  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Screen('Flip',display.windowPtr);  

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![mariokleiner](https://avatars.discourse-cdn.com/v4/letter/m/13edae/32.png) [@mariokleiner](https://psychtoolbox.discourse.group/u/mariokleiner)\
**Post date:** [September 26, 2016, 2:56pm UTC](https://psychtoolbox.discourse.group/t/mutliple-stimulus-with-1-screen/1238/2 "2016-09-26T14:56:30Z")

</div>

You just call Screen('DrawDots',...) again, providing the 2nd set of dots. All before the 'Flip' call.  
  
-mario
