• Remix
  • Share
  • New Entry

  • RENU

  • /
  • Under the sea

on 29 Nov 2023
  • 4
  • 5
  • 0
  • 0
  • 1083
drawframe(1);
Write your drawframe function below
function contestAnimatorWithoutPause()
animFilename = 'turtle_animation.gif'; % Output file name
firstFrame = true;
framesPerSecond = 24;
delayTime = 1/framesPerSecond;
% Create the gif
for frame = 1:48
drawframe(frame);
fig = gcf();
fig.Units = 'pixels';
fig.Position(3:4) = [800, 600];
im = getframe(fig);
% Convert to indexed image
[A, map] = rgb2ind(im.cdata, 256);
% Write to the gif file
if firstFrame
firstFrame = false;
imwrite(A, map, animFilename, 'gif', 'LoopCount', Inf, 'DelayTime', delayTime);
else
imwrite(A, map, animFilename, 'gif', 'WriteMode', 'append', 'DelayTime', delayTime);
end
% Wait for a short time (optional, for animation smoothness)
drawnow;
end
end
function drawframe(frame)
clf;
% Draw the ocean
drawOcean();
% Draw twinkling stars
drawStars();
% Draw the sky
drawSky();
% Draw the sea turtle
drawTurtle(frame);
% Drawnow to update the figure
drawnow;
end
function drawOcean()
% Draw the ocean background
rectangle('Position', [-1000, -1000, 2000, 2000], 'FaceColor', [0, 0, 0.5]);
end
function drawStars()
% Draw twinkling stars
numStars = 50;
starsX = rand(1, numStars) * 2000 - 1000;
starsY = rand(1, numStars) * 1000 - 500;
scatter(starsX, starsY, 5, 'w', 'filled');
end
function drawSky()
% Draw the sky background
rectangle('Position', [-1000, 500, 2000, 500], 'FaceColor', [0, 0, 0.2]);
end
function drawTurtle(frame)
% Example: You need to replace this with your turtle image or drawing
% For simplicity, I'm just drawing a basic shape
turtleSize = 50;
turtleX = -500 + frame * 20;
turtleY = -200;
rectangle('Position', [turtleX, turtleY, turtleSize, turtleSize], 'Curvature', [1, 1], 'FaceColor', [0, 0.8, 0]);
end
Animation
Remix Tree