- /
-
Lake view to the North
on 2 Nov 2024
- 59
- 371
- 0
- 4
- 1971
Cite your audio source here (if applicable): Voyage to Avalon, Kenji Kawai, 2001
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent I1 l
if f==1
%Declare functions to save space
u=@linspace;
e=@rescale;
n=@normpdf;
h=@flipud;
z=@zeros;
l=@repelem;
M=@repmat;
d=@rand;
b=@randi;
q=1000;
st=30; %number of striations
cb=4; %number of colorbands (note if this increases > 3, more RGBs will be needed
%makes a matrix of stars, initially these are 2x4 rectangles as every
%other pixel will be taken later
m=l((d(q/4,q/2)/.5+.5).*floor(b(3*q/2,q/4,q/2)/(3*q/2)),4,2);
m(m~=0)=1;
%vector of values as basis for drawing image
X=u(-1,1,q);
[th1, r1] = cart2pol(X,X');
th=u(pi,2*pi,st*2);
%matrix of coords to draw into
[y,x]=meshgrid(X);
k1=erf(abs(ifft2(exp(6i*randn(q))./(X.^2+X'.^2+9e-5)))); %rock texture from Tim!
a1=z(q);
a2=a1+1;
a2(x<(.3*(3*-y.^2+3*k1(1,:))+.8))=0;
M3=M(.55*k1.*a2,1,1,3);
M3(:,:,2)=M3(:,:,2)*1.2;
%y offsets of the striations - in an arc
yo=z(st,cb,96);
el=-[sin(th(1:st).') sin(th(st+1:2*st).') ]-.5;
yo(:,:,1)=[el-.5 el-1.4];
%medium offsets for the first 2 striations in each colour band
yo(1:4,:,1)=[z(4,2)-.3 z(4,2)-1.2];
%yo: pregenerate Y offset jitter to return to baseline within 96 frames (to
%avoid jumps between the segments of the movie stitched together by
%contestMovieGenerator
%ic: pre-generate increments in x position of striations to go back to starting position
%over 96 frames
ic=z(st,cb,96);
ic(:,:,1)=1.5*(sort(d(st,cb))-.5);
ic(1:2,1:cb,1)=z(2,cb);
ic(3:4,1:cb,1)=z(2,cb)+(d(2,cb)-.5);
for p=1:47
ic(:,:,p+1)=ic(:,:,p)+(d(st,cb)-.5)/80;
yo(1:4,:,p+1)=yo(1:4,:,p)+.15.*(d(4,cb)-.5);
yo(5:end,:,p+1)=yo(5:end,:,p)+.1.*(d(st-4,cb)-.5);
end
for p=1:48
ic(:,:,p+48)=ic(:,:,49-p);
yo(:,:,p+48)=yo(:,:,49-p);
end
%x offsets of 3 main colour bands
o=[-.7 .7 -.7 .7];
%Gaussian standard deviations of striation bands
wg=.008+(z(st,cb));
wg(1:2,:)=.5*ones(2,cb); %large standard deviations for 2 bands in each colour
wg(3:4,:)=.2*ones(2,cb);
%start and end RGB values per colour band
R2=[1 .49 .45 .84 .74 .66
.83 .07 .30 .66 .71 .64
.70 .89 .82 .47 .74 .29];
R2(4,:)=R2(3,:);
%standard deviation of striations in the Y
yg=(d(st,cb)+.3)./3;
%large stanard deviations for the first 2 striations in each colour
%band
yg(1:4,:)=z(4,cb)+.5;
%opacity of each colour band
ap=[.9 .9 .7 .7];
%angles of striations in each colour gradient
an=[u(-.25,0,st)
u(0,.25,st)];
an=[an;an];
%striation jitter in angle
aj=(d(st,1)-.5)*.08;
% decides whether striations will be increments or decrements in
% intensity
mu=round(d(st,cb)+.2)*2-1;
%first 2 in each band are always increments
mu(1:2,:)=ones(2,cb);
mu(3:4,:)=-ones(2,cb);
m6=e(n(x,-.3,.8),0,1); %these matrices the position of the colour bands (Gaussian filter)
m7=e(n(x,.5,.8),0,1);
x2=h(x+.4); %these matrices control the position of the colour gradients behind the aurora bands
x3=h(x+1);
I1=z(q,q,3,48); %declare large image matrix
ps=u(.5,.8,10)
for fg=1:48 %make 48 frames (animation changes every 2 frames)
fm=z(q,q,3);
%This is done for each frame
for i1=1:cb
a=a1;
for j=1:st
%rotate the x and y matrices to achieve striations at an angle.
%Includes jitter.
y1=y*cos(an(i1,j)+aj(j))+x*sin(an(i1,j)+aj(j));
x1=y*sin(an(i1,j)+aj(j))+x*cos(an(i1,j)+aj(j));
%this is the line that creates 24 striation layers on each frame
%and adds them to the current matrix for the frame. The y1 part
%does the striation in the x direction. The x1 part puts a Gaussian
%envelope in the vertical Y direction, also with jitter. The wg
%part scales the intensity of the striation inversely to the
%standard deviation. Adjusting the .^7 parameter can change the
%results.
a=a+mu(j,i1)*(wg(j,i1).^ps(randi(10))).*e(n(y1,ic(j,i1,2*fg)+o(i1),wg(j,i1)),0,.2).*e(n(-x1,yo(j,i1,2*fg)+.3,yg(j,i1)),0,.2);
end
%compiles the matrix for each colour band in a cell array, applies a
%vertical mask to create the vertical gradient to black (well, rotated
%vertical)
p1{i1}=a;
%Creates an RGB matrix for one of the colour bands as a straight
%gradient in the Y direction
mm=m7;
xx=x3;
for j=1:3
if i1<=2
mm=m6;
xx=x2;
end
%combines aurora Gaussian mask with color gradient matrices with RGB applied, different
%for the upper and lower aurora bands
b1(:,:,j)=mm.*(xx.*R2(i1,j)+(1-xx).*R2(i1,j+3));
end
%combines the RGB matrix with the striations to create striated colour
%matrices. Saves one for each of the 3 colour bands in a cell array
fm=fm+b1.*M(e(p1{i1},-.1,ap(i1)),1,1,3);
end
fm(M3>0)=M3(M3>0);%add mountain
%Creates star twinkles
m1=m.*(d(q)*.5+.3);
m1(M3(:,:,1)>0)=a1(M3(:,:,1)>0);%remove any stars from inside mountain
m1=[m1(1:2:end,:);h(m1(1:2:end,:))]; %reflect stars
%combines the 3 RGB images into one RGB matrix
fm1=fm(1:2:end,:,:);
fm2=h(fm1).*.5; %reflects and darkens the main image
for k=1:q/2
fm2(k,:,:)=circshift(fm2(k,:,:),b(15),2); %creates ripples
end
I1(:,:,:,fg)=M(m1,1,1,3)+e([fm1;fm2].*e(-r1,0,1),0,1); %creates the image by combining the reflected and unreflected elements and the stars. Rescales.
end
end
b1=l(1:48,1,2);
image(I1(:,:,:,b1(f))) %presents the RGB image, every other frame to slow down
camva(4.8)
end