• Remix
  • Share
  • New Entry

on 6 Nov 2023
  • 10
  • 45
  • 0
  • 3
  • 570
drawframe(1);
Write your drawframe function below
function drawframe(f)
% Seed the random number generator for reproducibility
rng(1);
% Define sphere
[X,Y,Z] = sphere(200);
R = 1-(1-mod(0:.1:20,2)).^2*.06;
x = R.*X;
y = R.*Y;
z = R.*Z;
c = hypot(hypot(x,y),z);
% Transformations for rotation
theta = f*pi/48; % Convert frame number to radians
rotation_matrix = [cos(theta) -sin(theta) 0; sin(theta) cos(theta) 0; 0 0 1];
% Rotate points
for i = 1:numel(x)
point = [x(i); y(i); z(i)];
rotated_point = rotation_matrix * point;
x(i) = rotated_point(1);
y(i) = rotated_point(2);
z(i) = rotated_point(3);
end
% Plot the rotated object
surf(x, y, (.8-(1:-.01:-1)'.^4*.1).*z*1.5, c+randn(201)*.027);
shading interp;
% Stem (not rotated for simplicity)
surface(X/12, Y/12, Z+.4, c-.12, 'FaceColor', '#652', 'EdgeColor', 'none');
% Set the color map to simulate speckles
colormap([1 .7 .1; .3 .4 .2]);
% Set aspect ratio and turn axes off
axis equal off;
% Set material properties and lighting
material([.6 1 .3]);
camlight;
end
Animation
Remix Tree