% Twinkle
% Displays stars and simulates twinkling.

% Close existing windows, force same scale in x and y directions, position
% the figure window, paint it black, and get ready to add stars...
close all
figure
axis equal off
set(gcf,'Position',[50 50 800 800],'Color','k')
hold on

% Star radius and the number of stars...
N = 50;

% Random coordinates of the stars....
x = randn(1,N); y = randn(1,N);

% Set the star radius so that it looks nice relative to the
% ranges of x and y

r = .03*max(max(x)-min(x),max(y)-min(y));

% Turn all the stars on...
for j=1:N
    DrawStar(x(j),y(j),r,'y')
end

title('Hit any key to begin simulation','FontSize',18,'Color','y')
pause

% Number of constellation twinkles...
T = 5; 
% The simulation
for k = 1:T
    % Visit every star in the constellation and turn it on or off
    % randomly...
    for j = 1:N
        if rand(1) < .5
            % Drawing a black star turns it off...
            DrawStar(x(j),y(j),r,'k')
        else
            % Drawing a yellow star turns it on
            DrawStar(x(j),y(j),r,'y')
        end
        % A brief pause will make for cool twinkling!
        pause(.01)
    end
end

hold off
