- /
-
Forge Ahead
on 26 Oct 2024
- 55
- 424
- 0
- 6
- 1895
Cite your audio source here (if applicable): Johnny Nash "I can see clearly Now", 1972.
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent c4 an x y z x1 y1 z1 x_1 y_1 z_1 x2 y2 z2 g RGB_image q b u n rw rw2
if f==1
c4=cat(3,.8,.8,.8);
an=linspace(0,237.66,97);
[x,y,z]=cylinder([.1 .5], 100);
[x1,y1,z1]=cylinder([.2 .3 .4 .5 .5 .4 .3 .2], 200);
x_1=-(z1-1)*6;
y_1=x1/2;
z_1=y1/2;
[x2,y2,z2]=sphere(99);
g=erf(z2*3);
%cloud image
u=@linspace;
n=@rescale;
b=@circshift;
q=1000;
m1=ones(q,q,3);
a=1.65;
m=0;
X=u(-1,1,q);
[t,r]=cart2pol(X,X'); %create r matrix for filter in fourier transform
l1=d(r,a); %generate 3 cloud layers using filtered noise function
l2=d(r,a);
l3=d(r,a);
i1=round(u(1,q,96)); %create 2 sets of indices for slow and fast moving cloud layers
i2=round(u(1,2*q,96));
[x_c,y_c] = meshgrid(0:999);
%smaller first constant creates wider cloud band (line below).
M3 = exp(-.0005*(y_c-300).^2/4^2); % gaussian envelope in matrix to keep clouds in a specified band.
M4 = exp(-.0005*(y_c-340).^2/4^2); % gaussian envelope in matrix to keep clouds in a specified band.
s1=[199 238 244]./255;
s2=[3 104 165]./255;
%create sky gradient
si(:,:,1)=n(y_c,s2(1),s1(1));
si(:,:,2)=n(y_c,s2(2),s1(2));
si(:,:,3)=n(y_c,s2(3),s1(3));
for k=1:96
a1_a(:,:,1)=l1.*M4;
a1_a(:,:,2)=b(l2,i2(k),2).*M3;
a1_a(:,:,3)=b(l3,i2(k),2).*M3;
a2_a(:,:,k)=(max(a1_a,[],3)); %blend 3 cloud layers using a max function
a2_b=max(a2_a(:))-a2_a;
RGB_image(:,:,:,k)=m1.*repmat(a2_a(:,:,k),1,1,3)+repmat(a2_b(:,:,k),1,1,3).*si;
end
RGB_image=n(RGB_image,0,1);
end
if mod(f,2)==1
rw=5*(randn(1081,1)-.5);
rw2=40*(randn(1081,1)-.5);
end
close all;
hold on
p(1)=surf(x,y,-(z-1)*10-10,0*x+c4); % Prop shaft
p(2)=surf(x_1,y_1-1,z_1,0*x1+c4);
p(3)=surf(x_1,y_1-1,z_1,0*x1+c4);
p(4)=surf(x_1,y_1-1,z_1,0*x1+c4);
rotate(p(2),[0 1 0],30+an(f),[0 0 0]);
rotate(p(3),[0 1 0],150+an(f),[0 0 0]);
rotate(p(4),[0 1 0],270+an(f),[0 0 0]);
r=@(g)surf(-x2*0.75,y2*0.9,g*.5-10,0*x2+c4);
r(g-1);
shading interp
view([0, 0]);
light('position', [-2, -2, 20], 'color', [.8, .9, 1]);
lightangle(-75,30);
material([.4, .4, 1, 4])
xlim([-13 13])
zlim([-23 13])
set(gcf, 'color', 'k');
axis equal off
hold off
hFig=gcf;
set(hFig,'Position',[0 0 2*q 2*q])
[X]=getframe(gcf);
X_f=X.cdata;
im=RGB_image(:,:,:,f);
im=repelem(im,2,2).*255;
%blend with background
X_f(X_f==0)=im(X_f==0);
%cut image at base of wind turbine
X1=X_f(150:1230,:,:);
X2=double(flipud(X1)-10);%darken sea
X3=flipud(im(150:1230,:,:)-10);
%circshift X2
for k=1:1081
X2(k,:)=b(X2(k,:),round(rw(k)),2);
X3(k,:)=b(X3(k,:),round(rw2(k)),2);
end
X4=uint8((X2+X3)./2);
X5=[X1;X4];
image(X5);
camva(4.8)
axis off
function c=d(r,a)
c=rescale(abs(ifft2(fftshift(fft2(randn(1000))).*(r.^-a))),0,1.2); %function to create clouds
end
end