function y = LineMotion(cuePos,cueLeadTime)
% LINEMOTION genetrates line motion display. 
% cuePos: cued location ('Left'or'Right', 'l'or'r')
% cueLeadTime: cue lead time (x  1/frame rate)

ShowCursor(0);	% arrowCursor
screenNumber=0;
[window,screenRect]=SCREEN(screenNumber,'OpenWindow',0);
displayWidth = screenRect(3) - screenRect(1);
displayHeight = screenRect(4) - screenRect(2);;
SCREEN(window,'SetClut',(0:255)'*ones(1,3));
SCREEN(window,'TextFont','Helvetica');
SCREEN(window,'TextSize',18);
flag = 1;

% Show a fixation 
SCREEN(window,'DrawLine',254,displayWidth/2-5,displayHeight/2,...
							 displayWidth/2+5,displayHeight/2,1,1);
SCREEN(window,'DrawLine',254,displayWidth/2,displayHeight/2-5,...
							 displayWidth/2,displayHeight/2+5,1,1);
% Wait click
SCREEN(window,'DrawText','Single click to start; Double click to quit',20 ,20);
clicks = GetClicks;
if clicks == 2  flag=0; end

while (flag)
	% Wait click
	
	% Show a cue
	if cuePos=='l' cuePos='Left'; end
	if cuePos=='r' cuePos='Reft'; end
	switch cuePos   % Second argument cuePos
		case 'Left'
			rect = [displayWidth/2-200-10,displayHeight/2+50-10,...
					displayWidth/2-200+10,displayHeight/2+50+10];
		case 'Right' 
			rect = [displayWidth/2+200-10,displayHeight/2+50-10,...
					displayWidth/2+200+10,displayHeight/2+50+10];
	end	
	SCREEN(window,'FillRect',254,rect);
	SCREEN(window,'WaitVBL', 2);
	SCREEN(window,'FillRect',0,rect); % Erase it
	
	% Show a line
	SCREEN(window,'WaitVBL', cueLeadTime);  % Set a cue lead time
	SCREEN(window,'DrawLine',254,displayWidth/2-200,displayHeight/2+50,...
								 displayWidth/2+200,displayHeight/2+50,10,10);
	SCREEN(window,'WaitVBL', 20);  % Duration of line
	SCREEN(window,'DrawLine',0,displayWidth/2-200,displayHeight/2+50,...
								 displayWidth/2+200,displayHeight/2+50,10,10); % Erase it
	
	% Wait click
	SCREEN(window,'WaitVBL', 30);
	clicks = GetClicks;
	if clicks == 2  flag=0; end
end

SCREEN(window,'Close');
