- /
-
Happy Diwali
on 2 Nov 2024
- 25
- 155
- 0
- 0
- 1985
Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
%if nargin == 0
% f = 1:96;
%end
persistent xP yP N sX sY rRate xl yl Ptrans
mhg = @(x,y,zrot,s) makehgtform('translate',[x y 0],'xrotate',-pi/2,'zrotate',zrot,'scale',s);
for iFrame = f
if iFrame == 1
%Start here
hFig = figure('Color','w','Visible','off');
text(0,0,{'Happy';'Diwali'},'FontName','Bookman Old Style','HorizontalAlignment','Center',...
'FontSize',28,'FontWeight','bold')
axis([-0.1 0.1 -0.1 0.1])
axis off
I = getframe();
close(hFig)
%downsample
a = squeeze(I.cdata(1:4:end,1:4:end,1));
a = flipud(a);
[yP,xP] = find(a<10);
N = numel(xP);
xP = [xP(setdiff(1:N,150)); xP(150)];
yP = [yP(setdiff(1:N,150)); yP(150)];
figure('Color','k'), hold on
camlight % This helps discern some the pumpkin details
light(St='l',Po=[2,2,1],Col='c') % Back light
lighting g
%Make some cheap pumpkins
P(1) = makePumpkin(20);
P(1).set('M',mhg(xP(1), yP(1), 2*pi*rand, 1));
for ii = 2:(N-1)
P(ii) = copyobj(P(1),gca);
P(ii).set('M',mhg(xP(ii), yP(ii), 2*pi*rand, 1));
end
P(N) = makePumpkin(200); %Make some nicer ones
P(N).set('M',mhg(xP(N), yP(N), 2*pi*rand, 1));
P(N+1) = makePumpkin(200);
P(N+1).set('M',mhg(min(xP)+23.5, min(yP)+2, 2*pi*rand, 4));
axis off
view(2)
xl = get(gca,'XLim')+[-10 10];
yl = get(gca,'YLim')+[-10 10];
sX = rand(N,1)*(xl(2)-xl(1))+xl(1);
sY = rand(N,1)*(yl(2)-yl(1))+yl(1);
rRate = rand(N-1)/5;
Ptrans = P;
end
ii = min(iFrame,80);
for jj = 1:N
curP = interp1([0 1],[sX(jj) sY(jj); xP(jj), yP(jj)],ii/80);
Ptrans(jj).set('M',mhg(curP(1), curP(2), rRate(jj)+ii*rRate(jj), 1))
end
Ptrans(N+1).set('M',mhg(min(xP)+23.5, min(yP)+2-40*(1-ii/80),4*pi*(iFrame/96),4))
ar = 10/7;
Z = [curP(1)+ar*[-1 1; -5 5],curP(2)+[-1 1; -5 5]; [xl yl]];
axis(interp1([0 0.2 1],Z,(ii-1)/80))
drawnow
end
end
function P = makePumpkin(n)
% Body
[X,Y,Z]=sphere(n);
R=(1-(1-mod(0:.1:n/10,2)).^2/12);
x=R.*X;y=R.*Y;z=Z.*R;
c=hypot(hypot(x,y),z)+randn(n+1)*.03;
H(1)=surf(x,y,(.8+(-linspace(1,-1,n+1)'.^4)*.3).*z,c,FaceC=[1,.4,.1],EdgeC='n');
% Stem
s=[1.5 1 repelem(.7, 6)].*[repmat([.1 .06],1,round(n/20)) .1]';
[t,p]=meshgrid(0:pi/15:pi/2,linspace(0,pi,round(n/10)+1));
H(2)=surf(repmat(-(.4-cos(p).*s).*cos(t)+.4,2,1),[-sin(p).*s;sin(p).*s],repmat((.5-cos(p).*s).*sin(t)+.55,2,1),FaceC='#008000',EdgeC='n');
P=hgtransform;
set(H,'Pa',P);
material(H,[.45,.7,.25]) % Pumpkin material
end