% oneThrow: Throw a single dart at a simple target
% Point (px,py) is where the dart lands
%
% Written by Paul Chew for CS100M, Feb 2006

close all                   % Close all previous figure windows

% Create the square (centered at origin; side length = 2)
hold on
axis('equal');              % Make the units the same length on each axis
axis([-1 1 -1 1]);          % Specify min and max values for each axis

% Compute position of "dart"
px = 2*rand - 1;
py = 2*rand - 1;
if (px^2 + py^2 <= 1)       % If within circle...
    plot(px, py, 'og');     % Hit
else
    plot(px, py, 'or');     % Miss
end
