Animated plot required to leave behind trace
This approach is slightly more complicated than corey979's but has the advantage that number of ghost lines is independent from the number of a
you want to use (in other words, the animation below is "continuous", not step by step).
aMax = 4; (* max value of a *)
n = 30; (* number of ghost lines *)
f[x_, a_] = 2 x a - a^2;
lines = Table[Line[{{-aMax, f[-aMax, a]}, {aMax, f[aMax, a]}}], {a,
Subdivide[-aMax, aMax, n]}];
showLines[a_] := Block[{},
pos = Position[Subdivide[-aMax, aMax, n], _?(# < a &)];
If[Length@pos > 0, Graphics[{Lighter[Blue, .4], lines[[;; Last@Last@pos]]}],
Graphics[]]]
list = Table[ Show[Plot[2 x a - a^2, {x, -aMax, aMax}, PlotRange -> {{-3, 3}, {-10, 7}},
PlotStyle -> Darker[Blue, .5]], showLines[a],
Frame -> True], {a, -aMax, aMax, 0.1}];
plots = Table[
Plot[2 x a - a^2, {x, -2, 2}, Filling -> Axis,
PlotRange -> {-5, 3}], {a, -1, 1, 0.1}];
frames = FoldList[Show, First @ plots, Rest @ plots];
(* or simply *)
frames = FoldList[Show, plots] (* thanks: Simon Woods *)
ListAnimate[frames, AnimationRate -> 2]
Exported
with
Export["plot.gif", frames, "DisplayDurations" -> 1/2]
My bid for your consideration. First I would simplify the Plot
to a single Line
segment, then abstract this to a function:
(* s = start; i = increment *)
fn[s_, i_][f_] := Line @ Table[{{-2, -4 a - a^2}, {2, 4 a - a^2}}, {a, s, f, i}]
From there I can animate smoothly as follows:
Animate[
Graphics[{{LightGray, fn[-2, 0.2][a]}, fn[a, 1][a]}
, PlotRange -> {-5, 3}
, AspectRatio -> 1/GoldenRatio
, Axes -> True
]
, {a, -2, 2}
, AnimationRate -> 1
, RefreshRate -> 60
, DisplayAllSteps -> True
]
Animation: