• Remix
  • Share
  • New Entry

on 29 Oct 2024
  • 14
  • 135
  • 2
  • 3
  • 2000
Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent P
a=@arrayfun;
c=@camlight;
C=[1 .4 .1];
d=24;
[x,y,x1,y1,x2,y2]=F(mod(f,d)-(ceil(mod(f,d)/d)-1)*d,d,a);
if f==1
figure(Color='k')
axes(Po=[0 0 1 1],Vis=0)
axis equal off
hold on
[~,~,~,P]=p(x,y,x1,y1,x2,y2,C);
a(@(x)light(St='l',Po=[0 0 0],Col='g'),1:4)
L=c('le');L.Color=C;
L=c('r');L.Color=C;
lighting g
campos([0 -75 5]);
camva(1.8)
else
[P.XData,P.YData,P.ZData]=p(x,y,x1,y1,x2,y2);
end
end
function [X,Y,Z,P]=p(x,y,x1,y1,x2,y2,C)
% Pumpkin
l=@linspace;
r=@repmat;
n=600;
% Body
[X,Y,Z]=sphere(n);
% Shape pumpkin ribs (ridges)
R=(1-(1-mod(0:20/n:20,2)).^2/12);
X=R.*X;Y=R.*Y;Z=Z.*R;
% Apply face mask
[X,Y,Z]=M(X,Y,Z,x,y,x1,y1,x2,y2);
Z=(.8+(0-l(1,-1,n+1)'.^4)*.3).*Z;
% Stem
s=[1.5 1 repelem(.7, 6)] .* [r([.1 .06],1,round(n/20)) .1]';
[t,p]=meshgrid(0:pi/15:pi/2,l(0,pi,round(n/10)+1));
x=r(-(.4-cos(p).*s).*cos(t)+.4,2,1);
z=r((.5-cos(p).*s).*sin(t)+.55,2,1);
y=[-sin(p).*s;sin(p).*s];
if nargout>3
P=surf(X,Y,Z,FaceC=C,EdgeC='n',SpecularS=.5,AmbientS=0,DiffuseS=.2);
S=surf(x,y,z,FaceC='#008000',EdgeC='n');
end
end
function [X,Y,Z]=M(X,Y,Z,x,y,x1,y1,x2,y2)
% Masking function
% Surface is in the form of
% -1 -1 . . . -1 -1
% . . . . . . .
% . . . . . . .
% 1 1 . . . 1 1
% Easy enough to mask w/ inpolygon (mask projected onto pumpkin)
i=@inpolygon;
% Rotate to align ribs with face
t=[-pi/2,0,0];
[X,Y,Z]=R(X,Y,Z,t);
% Mask
mask=ones(size(Z));
mask((i(X,Y,x,y)|i(X,Y,x1,y1)|i(X,Y,x2,y2))&Z>=0)=NaN;
Z=Z.*mask;
% Rotate back
t=[pi/2,0,0];
[X,Y,Z]=R(X,Y,Z,t);
end
function [X,Y,Z]=R(X,Y,Z,t)
% Rotation matrices from scratch because why not
Rx=[1 0 0;0 cos(t(1)) -sin(t(1));0 sin(t(1)) cos(t(1))];
Ry=[cos(t(2)) 0 sin(t(2));0 1 0;-sin(t(2)) 0 cos(t(2))];
Rz=[cos(t(3)) -sin(t(3)) 0;sin(t(3)) cos(t(3)) 0;0 0 1];
for i=1:size(X,1)
for j=1:size(X,2)
r=Rx*Ry*Rz*[X(i,j);Y(i,j);Z(i,j)];
X(i,j)=r(1);
Y(i,j)=r(2);
Z(i,j)=r(3);
end
end
end
function [x,y,x1,y1,x2,y2]=F(i,n,a)
% Face motion
l=@linspace;
f=@flip;
s=@size;
% Mouth
x=[0:.1:1,1:-.1:0]-.5;
y=[1 .5 .7 .1 .3 -.1 .3 .1 .7 .5 1;1 -.1 .1 -.5 -.3 -.7 -.3 -.5 .1 -.1 1]*.7-.45;
y=a(@(x)l(y(1,x),y(2,x),n)',1:s(y,2),Un=0);
y=[y{:}];
y=[y(i,:);y(end-i+1,:)];
y=[y(1,:),f(y(2,:))];
% Right eye
x1=[.15 .45 .45 .15]-.5;
y1=[1.2 1;2 1]*.7-.7;
y1=a(@(x)l(y1(1,x),y1(2,x),n)',1:s(y1,2),Un=0);
y1=[y1{:}];
if i<=ceil(n/2)
y1=[y1(1,:);y1(end-2*i+2,:)];
else
y1=[y1(1,:);y1(2*(i-ceil(n/2))-1,:)];
end
y1=[y1(1,:),f(y1(2,:))];
% Left eye
x2=[.35 .05 .05 .35];
y2=[1.2 1;2 1]*.7-.7;
y2=a(@(x)l(y2(1,x),y2(2,x),n)',1:s(y2,2),Un=0);
y2=[y2{:}];
y2=[y2(1,:);y2(end,:)];
y2=[y2(1,:),f(y2(2,:))];
end
Movie
Audio
Remix Tree