Does anyone know how to create a ghost trail effect? For a simple example look at this screenshot:
You can find the actual animation here. What I would ultimately like to see it happen is to make the object move based on whatever equations you specify it. For instance, to make it move around a circle the object should have the position (cos[t], sin[t])
. Or, lets say you have a list of specified coordinates {(x1,y1), (x2,y2), ..., (xn,yn)}
, All I want to be able to see is the trace as an object takes in the coordinates I specify.
Here is a simple ball moving without the ghosting effect.
Animate[
Graphics[
Disk[{Cos[u], Sin[u]}, .25],
PlotRange -> {{-2, 2}, {-2, 2}},
ImageSize -> 400,
Axes -> True
],
{u, 0, 6}
]
Answer
Here is a simple approach to create a ghost trail:
obj[{xfunc_, yfunc_}, rad_, lag_, npts_][x_] := MapThread[
{Opacity[#1, ColorData["SunsetColors", #1]],
Disk[{xfunc@#2, yfunc@#2}, rad Exp[#1 - 1]]} &,
Through[{Rescale, Identity}[Range[x - lag, x, lag/npts]]]]
frames = Most@Table[Graphics[obj[{Sin[2 #] &, Sin[3 #] &}, 0.1, 1, 500][u],
PlotRange -> {{-2, 2}, {-2, 2}}, Axes -> False, ImageSize -> 300,
Background -> Black] ~Blur~ 3, {u, 0, 2 Pi, 0.1}];
Export["trail.gif", frames, "DisplayDurations" -> .03]
Comments
Post a Comment