• Remix
  • Share
  • New Entry

  • Tim

  • /
  • Moon elevator

on 14 Oct 2024
  • 41
  • 432
  • 0
  • 1
  • 1476
Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
% This is supposed to be the view out of a window moving
% upward in the night sky. We will start with the window and
% create the clouds in the background,
persistent clr3 x d B
E='EdgeC';
F='FaceC';
l=@linspace;
if f==1
% Make a torus (for circular window)
N=200;
a=l(0,2*pi,N);
b=cos(a');
z=sin(a')*2.5;
x=b.*cos(a)+7*cos(a);
y=b.*sin(a)+7*sin(a);
[c,d]=meshgrid(l(-1,1,N)*8);
surf(x,erf(z/2)*2,y,F,[1,1,1],E,'none','DiffuseS',1,'AmbientS',.2);
hold on;
% Make the wall of the elevator
surf(c,.2*c.^2,d,E,'none',F,[1,.7,.5]);
% Make the window - make it black so we know where to add the scenery
[x,y,z]=sphere;
surf(x*6,y*6,z*6,F,'k','SpecularS',0);
hold off;
% Add a bit of color, pretty it, etc.
light('color',[1,.8,.2])
axis equal off
view([0, 0]);
camva(5);
G=gcf;
G.Position(3:4)=[600,600]; % Size for subsequent frames
% Get the image which will be used later as picture foreground
V=getframe(G);
B=V.cdata;
% Now our 3D noise. This will be similar to rolling fog, but larger.
% Multiple of 96 for seemless loop.
rng(1,'twister');
x=l(-1,1,480);
b=length(x);
d=x(1:3:end)/3; % This is the distance vector away from camera
c=length(d);
r=ifftshift(sqrt((x).^2+d'.^2+permute(x.^2,[1,3,2])));
% Not going to do any looping noise permutations in this one. It looks
% cool but slows things down, so will use a static noise realization.
enz=exp(2i*pi*randn(c, b, b))./max(r.^2.4,1e-5);
dt=5*abs(ifftn(enz));
h=.055*4;
ap=dt>h;
% Add glint from vertical direction but needs to be symmetric so the
% integrator will need to be fourier (vs. rolling fog's cumsum)
flt_cum=zeros(1,size(ap, 3));
flt_cum(1:100)=1;
flt_cum(101:150)=l(1,0,50);
flt_cum=fft(flt_cum);
% Thresholding, making alpha, etc.
c_alp=real(ifft(fft(ap,[],3).*permute(flt_cum,[1, 3, 2]),[],3));
CLS=(1.1-erf(c_alp/5)).*ap.*dt;
CLS(CLS>h)=h;
clr3=flip(CLS,3);
end
% Now, adding perspective. This is going to be done using a pin-hole camera
% model. This can be approximated by scaling things vs. range; this will be
% done using interpn. Re-scaling vs. range is done here:
[d2,d1,d3]=meshgrid(x,d,x);
scl=rescale(l(1,0,160)'.^2,.3,2);
clr4=interpn(d1,d2,d3,circshift(clr3, [0, -5*(f-1)*0, -5*(f-1)]),d1,d2.*scl,d3.*scl,'nearest',0);
% It looks really ugly to have massive pixels at close range, so this
% is a range-dependent 2D filter applied to each page of the noise
% function.
rflt=-erf((ifftshift(squeeze(sqrt(d2(1,:,:).^2 + d3(1,:,:).^2)))-permute(linspace(.8,.3,160).^2, [1, 3, 2]))*50)+1;
rflt=rflt./(max(rflt,[],[1,2])+eps);
fclr=abs(ifft2(fft2(permute(clr4,[2,3,1])).*rflt));
% Now apply the alpha channel to compress the volume into a 2D image
ffclr=flip(fclr,3);
alpha=ffclr;
As=alpha(:,:,1);
Ic=ffclr(:,:,1);
for nn=2:160
Ap=As;
As=Ap+alpha(:,:,nn).*(1-Ap);
Ic=(Ic.*Ap + ffclr(:,:,nn).*alpha(:,:,nn).*(1-Ap))./(eps+As);
end
% Finally, combine the foreground and imagery outside the window...
A=uint8(255*repmat(imresize(flipud(min(Ic*10,1)'),size(B(:,:,1))),[1,1,3]));
A(B~=0)=B(B~=0);
imshow(A);
end
Movie
Audio

This submission does not have audio.

Remix Tree