Chapter 9 : Animation

Remapping surfaces

Surfaces built with a mapper can be easily remapped, i.e. that having their Z coordinates updated due to a change in the z=f(x,y) which is parameterized by anything, e.g time.

The code below shows a SingleParameterMapper that evolves with IncreaseParamRemapTask :

public void init(){

  Mapper mapper = new SingleParameterMapper(0.999){
    public double f(double x, double y) {
      return 10*Math.sin(x*p)*Math.cos(y*p)*x;
    }
  };

  Shape surface = new SurfaceBuilder().orthonormal(new OrthonormalGrid(range, steps), mapper);

  [...]

  IncreaseParamRemapTask remap = new IncreaseParamRemapTask(surface, mapper);

  Thread thread = new Thread(remap);
  thread.start();

}

Where the implementation of the remap task is defined with :

public class IncreaseParamRemapTask extends AbstractRemapTask {
  [...]

  public void remap() {
    mapper.setParam(mapper.getParam() + increment);
    mapper.remap(surface);
  }
}

AnimatedSurfaceDemo

animateSirf

Adding and removing drawables dynamically

One can add and remove elements from the scenegraph by using its add(…) and remove(…) methods. These two methods can also be called with a boolean flag that indicates if the view bounds should be updated immediately or not.

Not updating the view immediately can be usefull if you need to add multiple objects. It prevents from intermediate rendering at each drawable addition.

chart.getScene().getGraph().add(line1);
chart.getScene().getGraph().add(line2);
chart.getView().updateBounds();

or

chart.getScene().getGraph().add(line, true);

AddRemoveElementsDemo

addRemove