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.

As you asked for, I've added the gif animation code to R.M's answer - the "DisplayDuration" setting is measured in seconds, and as far as I know one shouldn't go below 0.03 to avoid display problems in certain browsers.
–
JensApr 28 '12 at 3:07

In trail, fun is the path of the particle, tmin is the starting time, tmax is the current time, dt is the step size in time, and {xxx, yyy} are the coordinates at which you want to evaluate the function. The parameters k and lam determine the length and width of the trail where greater values for the parameters correspond to shorter/narrower trails.

Very nice indeed! +1 and if I could I would give some more.
–
LouApr 28 '12 at 15:09

I love the graphics, but, is it possible to show the axes also, maybe change the color scheme? I'm having trouble doing the pretty rendering with a set of fixed points using the function Interpolation, any ideas of how to make it faster?
–
jmlopezApr 28 '12 at 18:06

I saw this question rather late, and I can't quite hope to outdo the very fine answers already given, so please allow me to share my modest attempt at a three-dimensional implementation of the ghost trail:

I only wish to note three cute things about this particular implementation (that is, apart from the additional degree of freedom (via ViewPoint) provided by having three dimensions):

We can leverage the adaptive sampling capability of ParametricPlot3D[] so that the curve traced out by the ghost trail is sampled only where it matters. (If need be, trail[] can of course take the PlotPoints option.)

Tube[] supports a varying radius across its body. None of the two-dimensional primitives have an equivalent capability.

The Opacity[] directive in the ColorFunction option setting, in addition to its obvious purpose, allows the trapping of the (scaled!) parameter values used in the sampling of the curve. These values are then easily retrieved for the conversion into the list of radii needed by Tube[].

As with R.M, I shall be using a Lissajous curve (the three-dimensional equivalent in this case) to demonstrate trail[]:

In version 9, there is a new command ReplaceImageValue, and that got me thinking if it could be used to superimpose images more quickly. As an application, this question seemed to be a good illustration, especially under the aspect of speed.

Here the mouse controls where the ghost trail is heading. It follows the mouse in real-time.

To really exploit ReplaceImageValue here, I defined the bright spot in stencil as a disk with a gradient of colors using DiskMatrix[7] and assigning colors based on the distance from a point near its center. I deliberately offset that point: it's the subtracted value in Norm[# - {10, 9}]. If you replace {10, 9} by {8,8} you'll see that the offset gives the appearance of 3D lighting from one side.

To make the actual ghost trail, I used ImageMultiply on the currently displayed image im which darkens all pixels at every frame, so that the most recently added pixels from ReplaceImageValue appear brighter than the older pixels.

The position at which the stencil containing the disk is drawn is called q, and it gets updated by an increment in the function step which is directed toward the mouse but isn't allowed to jump too far ahead so that the trail doesn't get ripped into disjoint pieces (that's limited by the ArcTan).

Mathematica is a registered trademark of Wolfram Research, Inc. While the mark is used herein with the limited permission of Wolfram Research, Stack Exchange and this site disclaim all affiliation therewith.