• Remix
  • Share
  • New Entry

  • ME

  • /
  • Floating dots

on 16 Nov 2023
  • 9
  • 26
  • 0
  • 3
  • 470
drawframe(2);
Write your drawframe function below
function drawframe(f)
persistent B n X Y Z C % Define persistent variables used across frames
% Seed random number generator
rng(0);
% Clear axes
cla
hold on
% Set view properties for the figure
axis([-5 5 -5 5 -5 5])
set(gca,'Color','k','XTick',[],'YTick',[],'XDir','reverse','YDir','reverse')
camva(1.5)
% Define x,y,z coordinates of each dot and their respective colors and
% brightness
if(f==1)
n = 30; % Number of stars
X = 4*rand(1,n)-2; % Position
Y = 4*rand(1,n)-2;
Z = 4*rand(1,n)-2;
C = rand(1,n)*0.7 + 0.3; % Brightness Variation
if(f==1)
B(1,:) = (rand(1,n)); % Hue Variation
B(2,:) = (rand(1,n));
B(3,:) = (rand(1,n));
end
end
% Use scatter 3 to plot each dot
for k=1:n
r = 0.3*rand;
scatter3(X(k),Y(k),Z(k),5000*rand,[B(1,k) B(2,k) B(3,k)],'o','filled','MarkerFaceAlpha',r,'MarkerEdgeAlpha',1);
end
hold off
% Alter viewing position to give the impression of dots floating
view(-38+f*2,20-f*2)
end
Animation
Remix Tree