7.1. Basics

At the low-level, animation in Anableps (like everywhere) is done advancing the time in discrete steps and taking snapshots on each one.

In any scene in Anableps, there is a time variable. This variable commands the flow of time in the script. There is nothing special to this variable, other than the fact that every object and function will look to it to know which time is it. Change its value and objects that depend on it will move or change accordingly. If along this changes snapshots are taken, then all the requisites for producing a movie are met.

All this can be made explicitly by looping while changing t and taking snapshots but fortunately, Anableps provide better ways: the Movie object, is just a convenient way to store all the frames and from them, producing a video file. See the following example (animation.1)

## 1 ) prepare the scene:
c = cube .center 0 , 0 , {t + 23}  # we leave one dimension open:
                # as mutable expressions will be evaluated every time
                # any of its variables change.

# 2) create the movie:
Movie m: .camera c .size 400x400 .format gif

# 3) camera, action!
for t in 0..20 by 0.1:      # from 0 to 2 in steps of 0.1
  time = t                  # we change the system-var 'time'
                            # this changes c , as one of its
                            # dimensions depends on t, through
                            # a mutable expression.

  m.snapshot                # take the snapshot
end

# 4) save the movie
m.save .filename myMovie.mov   ## format is taken from filename
                               ## unless .format field present

In the previous example, there is something worth mentioning: open expressions. If we would have just typed:

c = cube .center 0 , 0 , t + 23

The cube would have been sitting at 0 0 23 all the time, as the expression would have been immediately evaluated. By enclosing it in braces, however, we define a mutable expression, one that must be evaluated at any time. This is the way to move objects

Movies have huge default capabilities. and Anableps will set a basic setup for you. For example, if you are just interested in a quick movie, you can try the following:

Movie m: .camera c  ## we set up the camera
m.record: .from 10 .to 20 .step 0.1  # sets the time intervals
m.save filename.gif

If nothing else is provided, the Movie object understands that you want to frame the whole scene and want some kind of a movie, so the camera will orbit the scene.

7.1.1. Moving things around

Movies other than a walk/fly-trough an scene need the objects to be moved or changed in some way. There are three general approximations to moving objects:

The most general option is to move the values explicitly in a time loop. This allows for super-fine detail but, may be, clumsier code:

cube c: .position 10 10 10 .size 20cm
movie m:

for t in [1..10]
    c.position t 10 10
    m.snapshot

m.save output.gif

Second option is using mutable expressions to set some variables. With that, the parameters will change when time advances:

cube c: .position {time + 2} 15 15 .size 20cm
movie m: .from 10 .to 20 .output movie.gif

Note the braces surrounding an expression: any object, when finding an expression retrieving a parameter, will evaluate the expression a parameter.

In this kind of animations, is very useful (although not mandatory) to use some available helper functions, defined so it is easier to code and understand:

  • travelling: this object makes a travelling from one point to other. It returns a coordinate system for the given time.

An example:

cube c: .size 20 cm
travelling t1: .from a .to .b .acceleration 2
camera c: position {t1}  # the camera performs a travelling

* travellings can be joined `t1 + t2`
* travellings can incorporate a zoom?
  • bouncing: what does bouncing?
  • orbiting: this object makes an orbit around one object.
  • zooming : this object performs a zoom to some part
  • linipol: a linear interpolation

Finally, the third option for animation is to use scripts, as described below.

7.1.2. Scripts

The higher level of abstraction for making movies is using scripts and movies to place and move objects. Scripts are very powerful and simplify a lot the process of rigging and moving the objects. See, for example, the following script:

movie m: asdfsaf
script {
    from 10 to 20 secs: bug1.moveTo p2
}

Bodies contain actions that take some time and detect time passing by. Whenever time is advanced, the function update() is called for _every_ object. In this way objects can define their own movements and stances, according with the time.

Todo

@TODO explanation of

7.1.3. Movie objects

As we just explained, movie objects are just a convenient form of grouping several functions commonly used to make animations. A movie object needs:

scene/canvas:the scene/canvas in which is going to record. Defaults to the current scene or canvas
camera:for scenes, a camera that record the process. Defaults to the scene’s default camera
renderer:the renderer that actually generates the pictures. Defaults to the current default’s renderer.

Additionally, it can contain an script object that sets everything in motion (see below)

To generate a movie, just call movie.record and produce a file:

example
movie m:
movie.record

Movies consisting on more than one shot, can be joined:

movie m = movie1 + movie.gap(2s) + movie2
m.save: .filename myMovie.gif

7.1.3.1. Saving

when the movie is finished, just type:

 movie.save <filename> .format <format> <other options>


:Video formats: Anableps deals with several video formats. The parameter are complex. See [[anableps video formats]] for a detailed explanation

7.1.3.2. rendering

Rendering a movie means rendering each frame and saving the results to a file (Currently, it is not possible to render a movie in memory and apply after-efects or whatever before writting to a file). To render a movie

In user-mode, rendering makes appear a progress-bar. To supress it, just change the .verbosity level to 0:

7.1.3.2.1. Calling for help

Movie rendering is one of the clear cases for parallelism. The render method of a movie can take hours, or days to complete. Of course, it is advised to try first with a fast renderer, like:

movie1.render .fast 30m

Thist will produce the full movie in 30m. Anyhow, at some point the full movie must be rendered, and here come slaves to help:

movie1.recruit 2

This recruits some slaves. Recruit parameter can be filled with a number (max number of slaves) or “all” or a tag that means that only those slaves with that tag will be recruited. Recruits return the number of slaves recruited. See the full reference at xxxxxxxxxx. For an explanation about how slaves and parallel computing work in Anableps: see chapter xxxxxxxxxxxxx

Technical note: when recruit is issued, the scene is sent to them. At this point, the scene becomes freezed.

7.1.3.3. Reference

render:starts the rendering .renderer .size

7.1.4. Scripts

Scripts are the way to set up complex animations in a simple way. Scripts are defined by giving actions

An script example:

 Script s {

  :scene 01:

  at 0.0 : {
      kid1.walk .from p1 .to p2    # these actions happen concurrently
      kid2.walk .from p1 .to p2
  }

  20 secs before : kid1.talk "asdfasdf" ## before referres to before end
  30 secs after: kid2.changeStance squat

  from 5secs to 20secs: camera.move .from camPos1 .to camPos2

  when kid1.idle and kid2.idle: kid3.walk : .from .to
  then: kid3.talk : "asdfsafasdf"                    ## then is when the last action finishes
  then {
      change scene.light .from 34 .to .duration 10secs  # change scene light
  }
}

Once the script is defined, the movie can be shoot using:

movie m1: .script myScript
m1.record .file wonderMovie.mpeg .fps 20 .frameSize 400x400 .color 16bit .compression max

In an script a camera can move (shape-shift) from one defined camera to another

7.1.4.1. Moving cameras

Example:

script s {
    from 5 to 20 secs: camera moves .to cam2 .acceleration 20  ## creates an interpolation
}

7.1.5. Complex Movies

Sometimes you have several movies and want to mount a frame with them:

movie movie1: .blah .blah   # just in case, try the parameter ".blah" two or more times in any object
movie movie2: .blah .blah
complexMovie movie3:
    # it mixes the movies somehow

7.1.7. Examples

Exploding a CAD design:

cad.explode

Fly-by, showcasing some object:

example