• Remix
  • Share
  • New Entry

  • Sai Teja G

  • /
  • Tribute to Indian Team for making Indians proud! #TeamIndia

on 20 Nov 2023
  • 9
  • 23
  • 0
  • 0
  • 1465
drawframe(1);
%Write your drawframe function below
function drawframe(frameNumber)
% Parameters for the flag's wave effect
numPoints = 1000;
x = linspace(0, 2*pi, numPoints); % Horizontal space for the flag
waveAmplitude = 0.1; % Amplitude of the wave
waveFrequency = 2; % Frequency of the waves
phaseShift = frameNumber * 0.15; % Phase shift for animation
yWave = waveAmplitude * sin(waveFrequency * x + phaseShift); % Wave equation
% Flag dimensions and colors
flagHeight = 2;
stripeHeight = flagHeight / 3;
saffron = [1, 0.52, 0.04];
white = [1, 1, 1];
green = [0, 0.6, 0];
chakraColor = [0, 0, 0.8]; % Navy blue for Ashoka Chakra
% Create the figure
fig = figure();
hold on;
% Draw the saffron stripe
fill([x, fliplr(x)], [yWave, fliplr(yWave + stripeHeight)], saffron, 'EdgeColor', 'none');
% Draw the white stripe
fill([x, fliplr(x)], [yWave - stripeHeight, fliplr(yWave)], white, 'EdgeColor', 'none');
% Draw the green stripe
fill([x, fliplr(x)], [yWave - 2 * stripeHeight, fliplr(yWave - stripeHeight)], green, 'EdgeColor', 'none');
% Draw the Ashoka Chakra
chakraRadius = stripeHeight / 2;
chakraCenterX = pi; % Center of the flag
chakraCenterY = yWave(round(numPoints/2)) - stripeHeight / 2;
numSpokes = 24;
for i = 1:numSpokes
angle = 2 * pi * (i - 1) / numSpokes;
spokeX = chakraCenterX + chakraRadius * cos(angle) * [1, -1];
spokeY = chakraCenterY + chakraRadius * sin(angle) * [1, -1];
plot(spokeX, spokeY, 'Color', chakraColor, 'LineWidth', 1.5);
end
viscircles([chakraCenterX, chakraCenterY], chakraRadius, 'Color', chakraColor, 'LineWidth', 1.5, 'EnhanceVisibility', false);
% Set the axis limits and aspect ratio
axis([0 2*pi -flagHeight flagHeight]);
axis equal off;
% Set the figure window size
fig.Position(3:4) = [600 300]; % Set figure size to 600x300 pixels
% Capture the frame
frame = getframe(fig);
im = frame2im(frame);
[imind, cm] = rgb2ind(im, 256);
% Filename for the GIF
animFilename = 'indian_flag_animation.gif';
% Write each frame to the GIF file
if frameNumber == 1
imwrite(imind, cm, animFilename, 'gif', 'Loopcount', inf, 'DelayTime', 0.1);
else
imwrite(imind, cm, animFilename, 'gif', 'WriteMode', 'append', 'DelayTime', 0.1);
end
% Close the figure to avoid excessive memory usage
end
Animation
Remix Tree