- /
-
Manta Race (other race pattern)
on 11 Oct 2024
- 11
- 110
- 0
- 0
- 1935
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 colors
if isempty(d)
set(gcf,'Color','k')
rng(0, "twister");
ydata = randn(100, 3);
v = violinplot(ydata);
colors = {[1 0 0], [0 1 0], [0 0 1]};
for i = 1:length(v)
v(i).FaceColor = colors{i};
end
numFrames = 24;
axis off;
xl = xlim; yl = ylim;
xlim([xl(1) xl(2)]);
ylim([yl(1) yl(2) * 10]);
r1 = randi(3, 1, 100);
endFlag = false;
nextFlag = false;
goalLineY = (yl(2) - 1) * 10;
hold on;
yline(goalLineY, 'LineWidth', 2, 'Color', 'y');
hold off;
d = 2;
win = 0;
end
if f == 1
cla;
ydata = randn(100, 3);
v = violinplot(ydata);
for i = 1:length(v)
v(i).FaceColor = colors{i};
end
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;
hold on;
yline(goalLineY, 'LineWidth', 2, 'Color', 'y');
hold off;
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)
if i == n
switch n
case 1 % red
newColor = [1, sin(tVal / numFrames * 4 * pi) * 0.5 + 0.5, sin(tVal / numFrames * 4 * pi) * 0.5 + 0.5];
case 2 % green
newColor = [sin(tVal / numFrames * 4 * pi) * 0.5 + 0.5, 1, sin(tVal / numFrames * 4 * pi) * 0.5 + 0.5];
case 3 % blue
newColor = [sin(tVal / numFrames * 4 * pi) * 0.5 + 0.5, sin(tVal / numFrames * 4 * pi) * 0.5 + 0.5, 1];
end
v(i).FaceColor = newColor;
else
v(i).FaceColor = colors{i};
end
end
for i = 1:length(v)
v(i).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', 'g', 'FontWeight', 'bold', 'HorizontalAlignment', 'center');
endFlag = true;
win = n;
end
else
if max(v(n).YData) > goalLineY
if (win ~= n)
if ~nextFlag
col = v(n).FaceColor;
else
col = col * 0.98;
end
text(n, max(v(n).YData) + 5, 'No!!', 'FontSize', 14, ...
'Color', col, 'FontWeight', 'bold', 'HorizontalAlignment', 'center');
nextFlag = true;
end
end
end
end
drawnow;
end