- /
-
Manta Ray
on 17 Oct 2024
- 84
- 1.03K
- 0
- 12
- 1955
Cite your audio source here (if applicable): Submerged / The Guild of Ambience : https://www.youtube.com/watch?v=PrSXb44xu0s&t=1666s
drawframe(1);
Write your drawframe function below
function drawframe(f)
l=@linspace;
N=255;
[z,y,x]=cylinder(ones(1,N),N-1);
zt=y.*(1-x)/33;
xt=z.*(1-x)/20;
yt=-x-.2;
x=(x-.5)*3;
z=z./abs(z).*(1-y.^6).*(1-(x/1.5).^6)/20; % Compress & taper in z
g=@(x,y)exp(-x.^2*y);
z(z>0)=z(z>0)+.1*erf(3*g(x(z>0)*1.4,15).*erf(exp((y(z>0)-.6)*3)).*(1-y(z>0).^12));
y=y.*(((erf(-y*2)+1)/2).*cos(abs(x)+1)+1.2)/2;
y=y.*(cos(x*2)+1.5)/3;
y=(y+.05).*(1-(x/max(x(:))).^16);
w=(erf((y-.5)*10)+1)/2;
z=z-w.*erf(exp(-x.^2*50))/10;
y=y+w.*erf(10*exp(-x.^2*30))/4;
n=nan(1,N);
x=[x;n;xt];
y=[y;n;yt];
z=[z;n;zt];
% Right - now let's make the caustics / light patterns. Let's make actual
% caustics; e.g. make a rippled surface and use Snell's law to bend rays.
N=96;
cx=l(-1,1,N);
cxu=l(-1,1,N*4);
[cx2,cy2]=meshgrid(cxu*2,cxu*2);
ag=l(0,2*pi,97);
% Now for some other animation details
xs=3;
ys=2;
agf=l(0,4*pi,97);
ags=sin(agf)+1e-6;
rgs=sin(ag)/4;
egs=-cos(agf)/3;
clsf=(rescale(-z).*cat(3,.8,.6,.5));
cls2=(rescale(-z).*cat(3,0,.5,.8));
cm=min(abyss.*linspace(0.4,1.5,256)',1).^.7;
rng(3,'twister');
RR=rand(10,1);
rp = 2*pi*RR;
n=f;
bck=sum(sin(l(0,13,300).*RR*10-2*ag(n)+rp)/40)+l(-.8,1.2,300)';
b=ags(n);
r=xs/b;
zc=z-((x.^2+.1).*sin(y*5+agf(n)+.4)/5);
[zo,xo,yo]=sph2cart(x/xs*b+rgs(n),y/ys*b+egs(n),(zc+r));
[zb,xb,yb]=sph2cart(rgs(n),egs(n),r);
zo=zo-zb+ags(n)/4;
xo=(xo-xb)+.3*rgs(mod(n-1+45,96)+1);
yo=yo-yb;
% Update ripples
pzr=exp(2i*pi*rand(N));
H=real(ifft2(circshift(fftshift(exp(1i*ag(n)*2*4)*pzr./(cx.^2'+cx.^2+4e-3)),[4,4])))/2e3;
k=hann(9);
H=repmat(circshift(ifft2(fft2(k*k',N,N).*fft2(H)),[-1*(n-1),0]),4,4);
[a,b,c]=surfnorm(cx2,cy2,H);
d=cat(3,a,b,c);
% Incident angle
u=.8;
I=cat(3,0,0,1);
T=sqrt(1-min(u.^2*(1-c.^2),1)).*d+u*(I-c.*d);
% Calculate ray / plane intersections...
t=(H-3)./T(:,:,3);
xf=cx2+T(:,:,1).*t;
yf=cy2+T(:,:,2).*t;
% Let's get our distances...
[IDX,D]=knnsearch([xf(:),yf(:)],[x(:),y(:)],'k',30);
clr=reshape(sum(exp(-D*30),2),size(x));
clr(z<0)=max(clr(:)*.7);
cpz=[-3,-4,3];
cdst=sqrt(sum((cpz(:)-[xo(:),yo(:),zo(:)]').^2));
wt=reshape(erf((cdst-5.8)*2)/2+.5,size(zo));
surf(xo,yo,zo,(cls2.*wt+clsf.*(1-wt))+(clr-10)/15,'EdgeC','none','SpecularS',0);
hold on;
[xp,zp]=meshgrid(-10:1:10);
yp=ones(size(xp))*5;
xp=xp.*l(4,.5,21)';
surf(xp/2,yp/2,zp/2-3,bck,'FaceC','texturemap','EdgeC','none','AmbientS',1);
colormap(cm);
caxis([-.6,1.4]);
hold off;
light('position',[-1,1,3]);
axis equal
camproj p
campos(cpz)
camtarget([0,0,0]);
camva(20);
set(gcf,'color',[0,.5,.7]);
axis off
end