- /
-
Manta Race
on 7 Oct 2024
- 15
- 312
- 1
- 5
- 1075
Cite your audio source here (if applicable):
drawframe(1);
Write your drawframe function below
function drawframe(f)
persistent v r1 endFlag nextFlag goalLineY numFrames
persistent d win xl yl col yrand
if isempty(d)
rng(0, "twister"); % for reproducibility
ydata = randn(100, 3);
v = violinplot(ydata);
numFrames = 24;
axis off;
xl = xlim; yl = ylim;
xlim([xl(1) xl(2)]);
ylim([yl(1) yl(2) * 10]);
r1 = randi(3, 1, 19);
endFlag = false;
nextFlag = false;
goalLineY = (yl(2) - 1) * 10;
yline(goalLineY, 'LineWidth', 2, 'Color', 'b');
d = 2;
win = 0;
end
nIndex = mod(floor((f - 1) / 5), length(r1)) + 1;
tIndex = mod(f - 1, 5) * d;
n = r1(nIndex);
tVal = tIndex;
for i = 1:length(v)
v(n).DensityWidth = sin(tVal / numFrames * 8 * pi) * 0.45 + 0.5;
v(n).YData = v(n).YData + 0.25 * d;
if ~endFlag
if max(v(n).YData) > goalLineY
text(n, max(v(n).YData) + 5, 'Win!!', 'FontSize', 14, 'Color', 'r', 'FontWeight', 'bold');
endFlag = true;
win = n;
end
else
if max(v(n).YData) > goalLineY
if (win ~= n)
if ~nextFlag
col = v(n).EdgeColor;
else
col = col * 0.98;
end
text(n, max(v(n).YData) + 5, 'No!!', 'FontSize', 14, 'Color', col, 'FontWeight', 'bold');
nextFlag = true;
end
end
end
end
drawnow;
if f >= 95 && ~endFlag
text(1, 0, 'Time Up!', 'FontSize', 14, 'Color', 'r', 'FontWeight', 'bold');
end
end