Wednesday, March 18

Lepton Particle Targeting

The other feature I alluded to in my last post was targeting, which allows you to specify specific starting and ending values for particle attributes and interpolate between them over time. This is used often in spontaneous arrangement effects, such as particles "imploding" from random directions into an orderly pattern, such as an image or logo. But many other effects are possible, since it gives you close control over arbitrary attributes and how they change over time without having to manage all of that complexity directly.

Here is how I envision particle targeting to work in Lepton:
  • Create a particle group to contain the "target" particles. Populate this group with particles with the desired final state for your interpolated particles.
  • Create a particle group to contain the interpolated particles with a target controller pointing at the target particle group.
  • Create or emit particles into the interpolated group however you see fit. Each new particle is matched with a particle in the target group. This matching can be done automatically or manually.
  • Each time the interpolated group is updated, particle attributes are interpolated between the initial particle state and the target particle state using a tweening function.
The magic happens in the target controller itself. When you instantiate it, you specify the target particle group, the attributes to interpolate, each attribute's tweening function and the particle age where it reaches its target. Since each interpolated particle can have a different initial age value, this means particles can reach their final state in different times. Typically the target particles would not be drawn or even change, but there would be no restriction on that and that could be used to create even more interesting effects.

Here's some theoretical sample code for targeting:
target_particles = ParticleGroup()
# ... populate target_particles ...
terps = ParticleGroup(
controllers=[
TargetRandom(target_particles,
position=EaseInOutQuad(10),
up=EaseInCirc(8)),
])
There will be several types of target controllers: Target will require interpolated particles to be matched to their targets manually, TargetRandom will randomly select targets, and TargetSequential will select targets in the order they occur in the target group. The interpolation behavior will be the same for these controller classes.

Interpolation of each attribute will be controlled by tweening functions. The keyword arguments passed to the target controller specify which particle attributes to interpolate and which tweening function to use. The simplest tween is just a linear interpolator, but more complex tweens, such as easings will create more natural looking movement and morphing. You can find a great discussion of tweening and easings in this document.

Labels: ,

0 Comments:

Post a Comment

<< Home