# Connect dots with mouseclick

**URL:** <https://psychtoolbox.discourse.group/t/connect-dots-with-mouseclick/3005>\
**Category:** Uncategorized\
**Created:** [January 28, 2020, 12:02pm UTC](https://psychtoolbox.discourse.group/t/connect-dots-with-mouseclick/3005 "2020-01-28T12:02:02Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marusama](https://avatars.discourse-cdn.com/v4/letter/m/b77776/32.png) [@Marusama](https://psychtoolbox.discourse.group/u/Marusama)\
**Post date:** [January 28, 2020, 12:02pm UTC](https://psychtoolbox.discourse.group/t/connect-dots-with-mouseclick/3005/1 "2020-01-28T12:02:02Z")

</div>

Hi, I’m new to psychtoolbox!

I have a code in which 5 dots with are randomly generated. I wanted to connect them with a line via mouse click.

first, here is the code:

clear;

ListenChar(1);  
Screen(‘Preference’, ‘SkipSyncTests’, 1);  
[p, frame] = Screen(‘OpenWindow’,0,[127 127 127],[],32,2);  
center = [frame(3)/2 frame(4)/2];

SetMouse(center(1),center(2)); %set mouse in centre  
[x, y, button] = GetMouse§;  
points = [x y];  
pressed = 0;

n = 5; %Number of dots  
rad = 10; %Radius of dots  
targ = ((rand(n,2).\*500)-250) + center;  
match = 0;

while button(2) == 0 %left button of the mouse

[x, y, button] = GetMouse§;

for i=1:n  
Screen(‘FrameOval’,p,[0 0 0],[targ(i,1)-rad targ(i,2)-rad targ(i,1)+rad targ(i,2)+rad]);  
end

match = find(sqrt((targ(:,1)-x).^2+(targ(:,2)-y).^2)\<=rad);  
if match\>0 Screen(‘FillOval’,p,[255 0 0],[targ(match,1)-rad+1 targ(match,2)-rad+1 targ(match,1)+rad-1 targ(match,2)+rad-1]); end

Screen(‘Flip’,p);

end

Screen(‘Closeall’);

I tried many things with button(1) ==1 but couldnt get any errors because I had to get off with the task manager.

I’m grateful for any help.

---

<div class="post-metadata">

**Author:** ![dcnieho](https://avatars.discourse-cdn.com/v4/letter/d/779978/32.png) [@dcnieho](https://psychtoolbox.discourse.group/u/dcnieho)\
**Post date:** [January 28, 2020, 12:39pm UTC](https://psychtoolbox.discourse.group/t/connect-dots-with-mouseclick/3005/2 "2020-01-28T12:39:47Z")

</div>

PsychDebugWindowConfiguration will help you interact with matlab while developing (makes the screen partially transparent)
