I have the following code, which accepts a function via an InputField
, and then gradually draws that function in a Plot
using Animate
:
Panel[DynamicModule[{f = "x^2-1", dummy = False},
Column[{Row[{InputField[Dynamic[f], String,
ContinuousAction -> True],
Dynamic[Button["Plot!", dummy = Not[dummy]]]}],
Dynamic[Animate[
Plot[If[x < Time, ToExpression[f], Undefined], {x, -5, 5},
PlotRange -> {{-5, 5}, {-5, 5}},
PlotStyle -> {Thick, Blue}], {Time, -5, 5},
LabelStyle -> White, AnimationRunning -> True]]}]]]
The problem is the animation is running constantly; and setting AnimationRepetitions->1
means that even after updating the function, the plot will stop redrawing. What I'd like to do is have it so that the Plot
region is only updated when the Plot! button is clicked. When it is clicked, the plot is drawn gradually, as above, but only once. To do this, I would need to be able to reset the animation from the Plot! button itself, and that doesn't seem possible. I thought Clock[]
might offer an elegant solution, but I think it is also impossible to reset those.
So, is there a way to do what I describe? Namely, have a graphics region that is only updated when a certain button is clicked, and when it updates an animation runs exactly once?