• Remix
  • Share
  • New Entry

  • Tim

  • /
  • Snowfall

on 1 Dec 2023
  • 20
  • 60
  • 1
  • 4
  • 1995
drawframe(1);
Write your drawframe function below
function drawframe(f)
clf
% Face parameters for the mother (right) and child (left) that control
% things such as cheek shape, general head structure, eyes (open v. closed)
HP=[2,4;.35,.45;8,4;.35,.3;.48,.52;1.28,1.32;2.3,2.2;1,-1;-.4,.3;.8,.75;4,20];
% Mother's face
[x,y,z]=face(400,HP(:,2));
% Rotation
a=@(x,y,r)x*cos(r)-y*sin(r);
b=@(x,y,r)x*sin(r)+y*cos(r);
% Plot
r=.17;
S=@(x,y,z)surf(x,y,z,'EdgeC','none','FaceC',[1,1,1],'DiffuseS',.2,'SpecularE',1,'SpecularS',1,'AmbientS', 0.0);
S(a(x,y,r)-.2,z,b(x,y,r)-.1);
axis equal off
set(gcf,'color','k');
% Light
light('pos',[-1.3,-1,.6]);
camzoom(2.8);
hold on;
% Child's face
[xa,ya,z2] = face(400,HP(:,1));
x2=a(xa,ya,.1);
r=.35;
S(-b(x2,z2,r)*.8-.8, a(x2,z2,r)*.8+.4, b(xa,ya,.1)*.8-.8);
camva(5)
campos([-7,-15,3]);
camtarget([-.6,0,-.45]);
rng default
N=99;
r=@rand;
a=r(N,1)*2*pi;
z=r(N,1);
a=a+(0:.25:2)*pi;
z=z.*ones(1,9);
d=r(N,1)*2+1;
d=d.*ones(1,9);
g=linspace(0,pi/4,49);
a=[a;a;a;a;a];
d=[d;d;d;d;d];
d=d(:);
z=[z;z-1;z+1;z-2;z+2];
c=a(:)+g(f);
scatter3(d.*cos(c)*2-.6,d.*sin(c)*2,z(:)-f/49,rescale(-d.*(cos(c)+sin(c)))*99+1,'w','filled','MarkerFaceA',.5);
plot3(0,1,-2,'k.','markers',1000)
end
function [x,y,z]=face(n,P)
% Start with a basic sphere
[x,y,z]=sphere(n);
% General distortions to make it more face like
z=erf(z*P(10));
x(y<0)= x(y<0)-abs(y(y<0)).^P(1)*P(2);
z(y<0)= z(y<0).*(1-.5*y(y<0).^P(3));
z(y>0)=z(y>0).*(1-.1*y(y>0).^2);
x(x<0)= erf(0.6*x(x<0))/0.6;
x(x>0)=x(x>0)*.9;
y(y>0)=y(y>0)*.9;
y=y+P(4);
z(y>0)=z(y>0).*exp(-x(y>0).^2/3).^y(y>0);
y=y-.3;
x=x+.6;
x(x>0)=x(x>0)*.9;
x=x-.6;
m=@(x,o,s).5-erf(-s*x+o).*erf(s*x+o)/2;
c=y(x<0);
c=1-exp(-(c+(exp(c*3)-0.4)).^2*3).*(.7*m(z(x<0),.8,10)+.3).*.1;
x(x<0)=c.*x(x<0);
fc=@(x)exp(-(-x+(exp(-x*9)-.6)).^2*2);
fc2=@(x)exp(-(-x+(exp(-x*2)-.6)).^2*2);
% Adding nose & lips
x(x<0)=((1-1*m(z(x<0),2,15)).*(fc(y(x<0)*1+P(5))*.15)+1).*x(x<0);
x(x<0)=((1-1*m(z(x<0),.7,8)).*(fc(y(x<0)*2+P(6))*.08)+1).*x(x<0);
x(x<0)=((.7-.7*m(z(x<0),0,8.5)).*(-fc(-y(x<0)*P(7)-1.71)*.06)+1).*x(x<0);
x=x+.5;
x(x>0)=x(x>0).*(1-.35*fc2((y(x>0)+.95)/1.4));
x=x-.5;
z=z.*(((x-.2).^2+(y+.4).^2).^.4*.2+.8);
x=x+.5;
% Adding eyes
[x,y,z]=ey(x,y,z,P,1);
[x,y,z]=ey(x,y,z,P,-1);
end
function [x,y,z]=ey(x,y,z,P,s)
b=@(x)tanh(exp(-4*abs(x).^2.5));
xt=(z(x<0)+s*0.33)*5;
yt=(y(x<0)+.145)*7;
ofs=max(b2(yt+P(8)*.2*xt.^2,P(9),P(11)).*b(sqrt(xt.^2+yt.^2)), b(sqrt(1.5*xt.^2+yt.^2))*.7);
x(x<0)=x(x<0)-ofs/20;
end
% Bump function with edge for eyes
function m=b2(x,of,s)
m=(erf((x+of)*s)/1.5+.5)+exp(-(x+(of-.1)).^2*10)/4;
%S.D.G.
end
Animation
Remix Tree