• Remix
  • Share
  • New Entry

on 3 Nov 2024
  • 23
  • 146
  • 0
  • 1
  • 1993
Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Function shorteners
C=@campos;
F=@flip;
A=@(a,b)[a F(-a) b F(-b)];
B=@(a,b)[a F(a) b F(b)];
% Decimal shorteners & character-saving combinations
s=.7; % Scale
c=.4;
d=.45;
e=.35;
n=.3;
g=.65;
h=.25;
l=.2;
m=.1;
o=.9;
q=.55;
r=.8;
u=[l .18 0];
v=-[0 m n n];
w=[0 1.5 3];
z=[c o];
% Draw the faces for masking
% Starting from the left
% Pumpkin 1
% % Mouth
x{1,1}=A(-[1 r n e .05 0],F(z));
y{1,1}=B([c l 0 -c -c -m],-z);
% Eyes
x{1,2}=[s n m];
y{1,2}=[z n];
% Pumpkin 2
% Mouth
x{2,1}=[-1 -r -c 0 m .15 d c z 1 o c -h -l -d -.5 -.9];
y{2,1}=[c l 0 -m -m -c -e 0 0 c r -z -o -g -g -r -c];
% Eyes
x{2,2}=[s l m];
y{2,2}=[.55 o n];
% Pumpkin 3
% Mouth
a=[o .6 .55 h l];
x{3,1}=A([-1 -g -.5 -.6 -h -.15 0],a);
b=-[z g g o];
y{3,1}=B([o l .05 -.23 -e -.08 -m],b);
% Eyes
x{3,2}=[s d m];
y{3,2}=[z e];
% Nose
x{3,3}=[-.17 0 .17];
y{3,3}=[l 0 l];
% Pumpkin 4
% Mouth
x{4,1}=x{3,1};
y{4,1}=y{3,1};
% Eyes
x{4,2}=[s m m];
y{4,2}=[e o e];
% Pumpkin 5
% Mouth
x{5,1}=A(-[1 g u],a);
y{5,1}=B([o v],b);
% Eyes
x{5,2}=x{3,2};
y{5,2}=y{3,2};
% Nose
x{5,3}=x{3,3};
y{5,3}=[0 l 0];
% Pumpkin 6
% Mouth
x{6,1}=A(-[1 r u],a);
y{6,1}=B([n v],b);
% Eyes
x{6,2}=[o h e];
y{6,2}=y{3,2};
% Pumpkins' centers
xc=[-3 -1.5 w 3.2];
zc=[w 1.5 0 -3];
% Compromises: Enforced symmetries, no characters left for rotation
if f==1
figure(Color='k')
axes(Po=[0 0 1 1],Vis=0)
axis equal off
hold on
for i=1:6
P(i)=p(x{i,1}*s,y{i,1}*s,-x{i,2}*s,y{i,2}*s,x{i,2}*s,y{i,2}*s,x{i,3}*s,y{i,3}*s);
set(P(i),'M',makehgtform(Translate=[xc(i) 0 zc(i)]));
light(St='l',Po=[xc(i) 0 zc(i)],Col='y')
end
lighting g
C([0 -48 5])
camva(9)
camlight('h')
else
a=1;
if f<49
a=-1;
end
b=10*sin(linspace(0,2*pi,97));
b=diff(b([f-1,f]));
C(C()+[b a b])
end
end
function P=p(x,y,x1,y1,x2,y2,xn,yn)
% Pumpkin
l=@linspace;
r=@repmat;
n=300;
p=pi;
% 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=R.*Z;
% Apply face mask
M
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,q]=meshgrid(0:p/15:p/2,l(0,p,round(n/10)+1));
x=r(-(.4-cos(q).*s).*cos(t)+.4,2,1);
z=r((.5-cos(q).*s).*sin(t)+.55,2,1);
y=[-sin(q).*s;sin(q).*s];
H=surf(X,Y,Z,FaceC=[1 .4 .1],EdgeC='n',SpecularS=.2,AmbientS=.3,DiffuseS=.7);
S=surf(x,y,z,FaceC='#008000',EdgeC='n');
P=hgtransform;
set([H,S],'Pa',P);
function M % Nested
% Masking function
i=@inpolygon;
% Rotate to align ribs with face
e(-p/2)
% Mask
m=ones(size(Z));
try
m((i(X,Y,x,y)|i(X,Y,x1,y1)|i(X,Y,x2,y2)|i(X,Y,xn,yn))&Z>=0)=NaN;
catch
m((i(X,Y,x,y)|i(X,Y,x1,y1)|i(X,Y,x2,y2))&Z>=0)=NaN;
end
Z=Z.*m;
% Rotate back
e(p/2)
end
function e(t) % Nested
% x-Rotation
Rx=rotx(rad2deg(t));
% 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)];
d=Rx*[X(i,j);Y(i,j);Z(i,j)];
X(i,j)=d(1);
Y(i,j)=d(2);
Z(i,j)=d(3);
end
end
end
end
Movie
Audio
Remix Tree