• Remix
  • Share
  • New Entry

  • ME

  • /
  • MATLAB in the stars

on 16 Nov 2023
  • 24
  • 48
  • 0
  • 1
  • 944
drawframe(1);
Write your drawframe function below
function drawframe(f)
rng(16112023,'twister');
% Obtain coordinates for membrane
xm = linspace(-1,1,31);
ym = xm;
zm = membrane;
cla % remove automatically plotted membrane surface
hold on
for i=1:31
Cm = rand(1,31)*0.7*((f)/48) + 0.3; % Brightness Variation
Bm(1:31,1) = (rand(1,31)/10+0.9).*Cm; % Hue Variation
Bm(1:31,2) = (rand(1,31)/10+0.9).*Cm;
Bm(1:31,3) = (rand(1,31)/10+0.9).*Cm;
ms = 8*(f/48)*rand(1,31); % Marker Size
% Plot glow for stars
scatter3(xm(i)*ones(1,31),ym,zm(i,:),40*ms,[Bm(:,1) Bm(:,2) Bm(:,3)],'filled','MarkerFaceAlpha',.2,'MarkerEdgeAlpha',.2);
% Plot markers for each star
plot3(xm(i)*ones(1,31),ym,zm(i,:),'*','Color','w');
end
axis([-5 5 -5 5 -5 5])
view(-38,20)
set(gca,'Color','k','XTick',[],'YTick',[],'XDir','reverse','YDir','reverse')
camva(1.5)
% Add 30 random stars in the background
n = 30; % Number of stars
X = 3*rand(1,n)-1.5; % Position
Y = 3*rand(1,n)-1.5;
Z = 3*rand(1,n)-1.5;
C = rand(1,n)*0.7*((f)/48) + 0.3; % Brightness Variation
B(1,:) = (rand(1,n)/10+0.9).*C; % Hue Variation
B(2,:) = (rand(1,n)/10+0.9).*C;
B(3,:) = (rand(1,n)/10+0.9).*C;
for k=1:n
ms = 8*(f/48)*rand;
% Plot glow for stars
scatter3(X(k),Y(k),Z(k),40*ms,[B(1,k) B(2,k) B(3,k)],'filled','MarkerFaceAlpha',.2,'MarkerEdgeAlpha',0.2);
% Plot markers for each star
plot3(X(k),Y(k),Z(k),'*','MarkerSize',ms,'Color',[B(1,k) B(2,k) B(3,k)]);
end
hold off
end
Animation
Remix Tree