% Author Suresh kumar Devanathan
% GNU License
clear
% screen 

s_x = 6000;
Screen = zeros(2,s_x);


% radial momentum 
avg_vx  =  300;
std_vx  =   10;

% experiments
N = 100;
Nexp = 300;
Nrep = 2000;

rput = 1:s_x;


for i = 1:Nrep
       
screen_x    = cumsum(avg_vx  + std_vx  * randn(Nexp,N), 2) ;

% reflection, refraction

screen_x   = screen_x(:, 60:100);

c0to10 = rand(1,1) > 0.5;
cxto10 = rand(1,1) > 0.5;

% contribution of distance delay from reflection
% refraction

screen_x =  screen_x(:) +  0.25* avg_vx *(  c0to10  + cxto10 ) ;


loc_x = round((screen_x- 20000) *  s_x/6000) ;
loc_mask =  (loc_x > 0) & (loc_x < s_x);
loc = nonzeros( loc_mask  .* (loc_x));

loc_up = histc( loc' ,  rput);

% appropriate bin
putin = mod(c0to10 + cxto10,2) + 1;

Screen( putin , rput ) = Screen( putin, rput )  + loc_up;

end;

plot(1:s_x, Screen(2,:), 1:s_x, Screen(1,:));

legend('Output 1','Output 0');
