• Remix
  • Share
  • New Entry

on 22 Oct 2024
  • 15
  • 145
  • 0
  • 1
  • 880
Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
% store axes handle
hAx = gca;
% default 3D view
view(3);
% X, Y, and Z coordinates of the path
t = linspace(0, 4*pi, 96);
x = (cos(t) + cos(5*t/2)) * 10;
y = (sin(t) + sin(5*t/2)) * 10;
z = sin(2*t) * 10;
% scaling for the leading markers in each frame
scaleList = repmat([1:12,12:-1:1],1,4);
% scaling for the current frame
scaleFactor = scaleList(f);
% sizes of the 12 leading markers
if scaleFactor==1 % if no scaling
sizeList = ones(1,12)*50; % then all markers have the same size
else
sizeList = linspace(50,50*scaleFactor,12).*linspace(1,scaleFactor,12);
end
% leading markers followed by a trail of markers with constant size
if f > 12
sizeList = [ones(1,f-12)*50,sizeList];
end
% array of RGB triplets specifying the color of each marker
colorList = hsv(96);
% shift by 2 idxs each frame
shiftNum = mod(f*2,96);
colorList = [colorList(shiftNum+1:end,:);colorList(1:shiftNum,:)];
if f==1 % if first frame
% create scatter to plot a marker for each frame
hScat = scatter3(x(1:f),y(1:f),z(1:f),...
'MarkerFaceColor',"flat",...
'SizeData',sizeList(1:f),...
'CData',colorList(1:f,:));
hold on
else % if after first frame
% change properties of scatter we already created
hScat = hAx.Children;
set(hScat,...
'XData',x(1:f),...
'YData',y(1:f),...
'ZData',z(1:f),...
'SizeData',sizeList(1:f),...
'CData',colorList(1:f,:));
end
% hide axes, set limits
set(hAx,...
'Visible','off',...
'XLim',[-20 20],...
'YLim',[-20 20],...
'ZLim',[-20 20])
% rotate the camera
rotateAngle = f * (360 / 96);
camorbit(rotateAngle, 1);
drawnow;
end
Movie
Audio
Remix Tree