• Remix
  • Share
  • New Entry

  • Nil

  • /
  • Underwater Scene Animation

on 29 Nov 2023
  • 3
  • 5
  • 0
  • 0
  • 821
drawframe(1);
Write your drawframe function below
function createAnimation()
% Parameters
duration = 12; % seconds
fps = 24; % frames per second
num_frames = duration * fps;
% Create Animation
for f = 1:num_frames
drawframe(f);
end
end
function drawframe(f)
persistent frames
if f == 1
% Parameters
duration = 12; % seconds
fps = 24; % frames per second
num_frames = duration * fps;
% Preallocate frames cell array
frames = cell(1, num_frames);
% Create each frame
for i = 1:num_frames
figure;
% Underwater Scene Animation
num_fish = 30;
fish_x = rand(1, num_fish) * 800 - 400;
fish_y = rand(1, num_fish) * 400 - 200;
fish_size = randi([10, 50], 1, num_fish);
% Plot fish
scatter(fish_x, fish_y, fish_size, 'b', 'filled');
% Plot seaweed
seaweed_heights = randi([20, 200], 1, 10);
seaweed_positions = rand(1, 10) * 800 - 400;
for j = 1:10
plot([seaweed_positions(j), seaweed_positions(j)], [0, seaweed_heights(j)], 'g-', 'LineWidth', 2);
end
% Plot ocean floor
plot([-500, 500], [-200, -200], 'k-', 'LineWidth', 2);
% Adjust plot settings
axis equal;
xlim([-500 500]);
ylim([-200 400]);
xlabel('X');
ylabel('Y');
title('Underwater Scene Animation');
% Capture frame
frames{i} = getframe(gcf);
close;
end
end
% Display frame
imshow(frames{f}.cdata);
axis off;
end
Animation
Remix Tree