I'm having trouble finding a way to play an animation (inside Manipulate
) if a certain condition is met.
I'm representing liquid volume with rectangles and if the controls result in the liquid volume exceeding 1 (liter), then the liquid should "drain" from the container. I have not been able to figure out how to run an animation inside Manipulate
that plays once and only if the volume limit is exceeded.
Here is a simplified version of the code, where vLIQ
represents the calculated volume:
Manipulate[
Module[{vol},
vol := If[vLIQ <= 1, vLIQ, 0];
Graphics[{
FaceForm[Opacity[0.6, Green]], Rectangle[{0, 0}, {0.5, vol}],
EdgeForm[Thick], FaceForm[None], Rectangle[{0, 0}, {0.5, 1}],
Thick, Black, Line[{{0, vol}, {0.6, vol}}],
Text[Style[vol, 16], {0.7, vol}],
},
ImageSize -> 230, PlotRange -> {-0.1, 1.1}, ImagePadding -> 10]],
{{vLIQ, 0.75, ""}, 0.25, 1.2, 0.1, Appearance -> "Labeled"}]
And the behavior I want to show (minus the animation of the green rectangle slowly going to zero if vLIQ
is greater than 1):