% SUNRISE AND SUNSET
% a student

% sun follows arc path from zero to pi
% colors change with sine curve from zero to pi,
%  where zero is darkest(black) and one is brightest

% sky
xb= [-10 10.1];
yb= [6 6];

% sun center
x0=7;y0=0;
r_ref=[x0;y0];

% sun lines
x1=[5.5 8.5 nan 7 7 nan 5.9 8.1 nan 5.9 8.1];
y1=[0 0 nan 1.5 -1.5 nan -1.1 1.1 nan 1.1 -1.1];
r_ref2=[x1;y1];

% left mountain
ltheta = linspace(0,-2*pi,100);
x2 = -10 + 20 * cos(ltheta);
y2 = -20 + 20 * sin(ltheta);

% right mountain
rtheta = linspace(0,2*pi,100);
x3 = 10 + 20 * cos(rtheta);
y3 = -20 + 20 * sin(rtheta);

% grass
x4= [-10 10.1];
y4= [-6 -6];

% tree trunk
x5= [5 5];
y5= [-3 3];

% tree top
x6=[5 5];
y6=[1 2.5];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

for i = linspace(0,pi,100)

v = sin(i);

bg=plot(xb,yb,'-b','LineWidth',130);
set(bg,'Color',[.2*v,.8*v,1*v]);
hold on

theta = i;

R = [ cos(theta)  -sin(theta);
      sin(theta)  cos(theta)];

r = R* r_ref;  %rotated sun center

xr=r(1,:);
yr=r(2,:);

r2 = R* r_ref2;  %rotated sun rays

xr2=r2(1,:);
yr2=r2(2,:);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

plot(xr,yr,'y.','MarkerSize',70);
axis off
axis('equal'); 
axis([-10 10 -10 10]);
hold on

plot(xr2,yr2,'y-','LineWidth',1);
hold on

a=plot(x2,y2,'-m','LineWidth',90);
set(a,'Color',[.8*v .1*v .8*v]);
hold on

b=plot(x3,y3,'-c','LineWidth',90);
set(b,'Color',[.1*v 1*v 1*v]);
hold on

c=plot(x4,y4,'-g','LineWidth',110);
set(c,'Color',[.1*v .9*v .1*v]);
hold on

d=plot(x5,y5,'-r','LineWidth',20);
set(d,'Color',[.7*v .3*v .2*v]);
hold on

e=plot(x6,y6,'g^','MarkerSize',45,'Linewidth',20);
set(e,'Color',[.1*v .9*v .1*v]);
hold on

shg
pause(.01)
clf

end