USA flag - MATLAB Shorts Mini Hack
  • Remix
  • Share
  • New Entry

on 23 Oct 2024
  • 15
  • 60
  • 0
  • 1
  • 1437
Cite your audio source here (if applicable): https://en.wikipedia.org/wiki/File:Star_Spangled_Banner_instrumental.ogg
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent g x y a
if f == 1
usflag
g = getframe(gcf).cdata;
g = g(end:-1:1,:,:);
close;
[s1,s2,~] = size(g);
[x,y] = meshgrid(1:s2, 1:s1);
a = 25 * (x/s1) .^ 0.5;
end
y2 = a .* sin((2*x + y + 200*pi*f/48) * 0.01);
z2 = y + 50 * sin(pi*f/96);
surf(x, y2, z2, g, 'edgec', 'n', 'AmbientStrength', 0.5);
camlight headlight;
axis equal off;
view([-40 20]);
end
function usflag
% Draws the United States flag, based on proportions from http://www.usflag.org.
% Red and blue colors are approximate, along with star inner radius.
% Requires star()
% Alain C. Barthelemy, abarthelemy@ieee.org
% 8 January 2002
%
% Usage:
% >> usflag
scr = get(0, 'ScreenSize');
sz_fac = scr(3)/7;
p = sz_fac.*[1 1.9 7/13 0.76 0.054 0.054 0.063 0.063 0.0616 1/13];
red = [0.8 0 0];
blue = [0 0 0.5];
wh = [1 1 1];
set(figure, 'Menubar', 'None', 'Position', [0 0 p(2) p(1)], 'Numbertitle', 'Off', 'Name', 'United States flag');
set(axes, 'YDir', 'reverse', 'Position', [0 0 1 1], 'XLim', [0 p(2)], 'YLim', [0 p(1)], 'Visible', 'Off');
patch([0 p(2) p(2) 0 0], [0 0 p(1) p(1) 0], wh); % White background for flag
for stripe = 1:7 % Red stripes
patch([0 p(2) p(2) 0 0], (2*p(10)*(stripe-1))+[0 0 p(10) p(10) 0], red, 'EdgeColor', red);
end
patch([0 p(4) p(4) 0 0], [0 0 p(3) p(3) 0], blue, 'EdgeColor', blue); % Dark blue for Union
for big = 1:4 % Fill in the stars
for star_ind = 1:6
star(p(9), p(7)+(star_ind-1)*2*p(8), p(5)+p(6)*2*(big-1), wh);
if star_ind < 6
star(p(9), 2*p(7)+(star_ind-1)*2*p(8), p(5)+p(6)+p(6)*2*(big-1), wh);
end
if big == 4
star(p(9), p(7)+(star_ind-1)*2*p(8), p(5)+p(6)*2*big, wh);
end
end
end
end
function star(r, mx, my, wh)
% Function to make star patches
th = linspace(0.3*pi, 2.3*pi, 6);
x1 = (r/2)*cos(th);
y1 = (r/2)*sin(th);
x2 = (r/2)/3*cos(th+0.2*pi); % One-third dimension is approximate
y2 = (r/2)/3*sin(th+0.2*pi);
xxx = [x1; x2];
yyy = [y1; y2];
patch(xxx(:)+mx, yyy(:)+my, wh, 'EdgeColor', 'n');
end

Show more

Movie
Audio
Remix Tree
Go to top of page