- /
-
Yurgen
on 24 Oct 2024
- 54
- 478
- 0
- 3
- 1897
Cite your audio source here (if applicable): Yurgen's Tune / Isaac Horn, Lincoln Mick & Sarah Wood / words by Andrew Peterson / music from the WingFeather Saga.
drawframe(1);
Write your drawframe function below
% Yurgen is a dragon in the WingFeather Saga by Andrew Peterson. A highly
% recommended book series for young & old readers. An animated adaptation can be
% viewed for free through Angel Studios.
%
% This dragon was inspired in part from Slandarer's marvelous submission
% Dragon in the deep sea
% (https://www.mathworks.com/matlabcentral/communitycontests/contests/8/entries/16319)
function drawframe(f)
nsg = 55; % Number of dragon segments
l=@linspace;
c=@circshift;
r=@interp1;
ll=l(-1,1,nsg);
tl=(erf(ll*5-1)+1).*l(2,0,nsg);
sd=tl./tl+2*exp(-(ll+.7).^2*100);
tp=erf(-ll*5+3)/2+.5;
% Basic segment creation
rd=.8:.05:1.1;
[x,y,z]=cylinder([0,rd,rd(end-2),0],24);
z(end-1,:)=z(end-3,:)+.05;
% Path & orientation vectors
t=l(0,2*pi,100)';
g=[sin(t),cos(t),sin(2*t+5)/2];
d=cumsum([0;sqrt(sum(diff(g).^2,2))]);
df=l(0,d(end),97);
df(end)=[];
gp=8*r(d,g,df);
d1=gp-c(gp,1);
d2=d1-c(d1,-1);
d1=d1/2+c(d1,-1)/2;
d2=-d2;
v=@(x)x./vecnorm(x')';
d1=v(d1);
d2=v(d2);
d3=cross(d1,d2);
dN=l(0,df(end)*.75,nsg);
% Dragon head
[q,w,e]=cylinder([0,.7,ones(1,15)],24);
lm=l(.7,2,17)';
q(5:9,:)=q(5:9,:)*.8;
w(5:9,:)=w(5:9,:)*.9;
w=erf(w.*lm/2-.8)*2+1.8;
t=zeros(1,25);
t(1:2:25)=.1;
t=t.*(erf((l(-1,1,17)-.5)*4)/2+.5)'+1;
q=.7*q.*lm.*t.^6;
w=w.*t.^6;
e=4*e.*t.^2;
q(10,[4,10])=0;
q(2,[3,11])=0;
n=f;
rr=@(v)r(df,c(v,n-1),dN);
id1=rr(d1);
id2=rr(d2);
id3=rr(d3);
igp=rr(gp);
xf=[];
yf=[];
zf=[];
for m = 1:nsg
rmat = [id3(m,:);id2(m,:);id1(m,:)];
rd=ones(1,25);
r2=rd;
r3=rd;
rd(2:2:end)=.9;
r2([7,19])=[tl(m)+1.1,tl(m)+1];
r3([15,7,23])=sd(m);
sc=ones(10,1);
sc(1:2:end)=1;
xn=x.*rd.*sc.*r2.*r3*tp(m);
zn=y.*rd.*sc.*r2.*r3*tp(m);
yn=2*z.*rd.*r2;
b=.85*[xn(:),zn(:),yn(:)]*rmat+igp(m,:);
rs=@(v,q)reshape(v,size(q));
xf=[xf;rs(b(:,1),x)];
yf=[yf;rs(b(:,2),x)];
zf=[zf;rs(b(:,3),x)];
if m==1
b=[q(:),w(:)-1,e(:)-2]*rmat+igp(m,:);
ch=bsxfun(@power,(cat(3,.4,.6,.8).*w./w),l(1,0,17)'.^.3);
ch(9:10,3:4,:)=cat(3,1,0,.4).*ones(2);
ch(9:10,9:10,:)=cat(3,1,0,.4).*ones(2);
surf(rs(b(:,1),w),rs(b(:,2),w),rs(b(:,3),w),ch,'AmbientS',.3);
hold on;
end
end
sd2=sd.*ones(10,1);
tl2=tl.*ones(10,1)+1;
a=xf./xf;
a(:,[7,15,19,23])=([sd2(:).*tl2(:),sd2(:),tl2(:),sd2(:)]<1.1);
b=imdilate(1-a,ones(1,3));
b=b./b;
a=a./a;
cf=permute(r([0,1]',[1,.9,.9;1,.2,.3],l(0,1,550)'),[1,3,2]);
c2=cat(3,.4,.6,.8).*ones(550,25);
surf(xf.*b,yf.*b,zf.*b,cf.*ones(1,25),'AmbientS',.8,'SpecularS',1,'DiffuseS',1);
surf(xf.*a,yf.*a,zf.*a,c2,'AmbientS',.3,'DiffuseS',1);
shading flat
hold off;
axis equal off
light('position',[0,0,1]);
camproj p
campos([-1,-1,0]*40)
camva(15);
camtarget([0,0,.5]);
set(gcf,'color',[0.05,0,.1]);
end