Main question
The following animation runs smoothly in my Wolfram Desktop. However, it's extremely choppy in the cloud notebook I published it to. I tested it in Firefox and Safari, and it's choppy in both.
Here's a link to the notebook... scroll down to the very bottom of the page to see the relevant animation:
https://www.wolframcloud.com/obj/jonahx/Published/Riddler10-22-21.nb
Is this a bug in the cloud notebook, or are there configuration options I should be using to make it work more smoothly?
Related Question
What is the most efficient way to create a video of this animation?
One method that I tried, which worked but was slow, was to convert the list of Graphic
objects to a list of Image
objects, and pass that list to AnimatedImage
. Is there a better approach?
Code
So that this question will be self contained for posterity, here's the code for animation:
randpt[x_, y_] := (
r = RandomReal[];
r x + (1 - r) y
);
a = {0, 0};
b = {1, Sqrt[3]};
c = {2, 0};
randtri[] := {
randpt[{0, 0}, {1, Sqrt[3]}],
randpt[{0, 0}, {2, 0}],
randpt[{2, 0}, {1, Sqrt[3]}]
};
center = {1, 1/Sqrt[3]};
cnt = 0;
n = 500;
gs = {};
For[i = 0, i < n, i++, (
hull = ConvexHullMesh[randtri[]];
cnt += If[RegionMember[hull, center], 1, 0];
AppendTo[
gs,
Graphics[{
{If[RegionMember[hull, center], Red, Green], hull},
{EdgeForm[Thick], Transparent, Triangle[{a, b, c}]},
{Red, PointSize[.02], Point[center]},
{Text[
Style[
"Step: " <> ToString[i] <> ". Estimate: " <>
ToString[N[cnt/(i + 1), 2]], Large], {2, 2}]},
}]
];
)
]
Animate[
gs[[i]],
{i, Range[Length[gs]]},
AnimationRate -> 2,
SaveDefinitions -> True
]