5 Animations

▼ |  | Slideshow: Figure and Presentation Tools

1 | Creating Slide Presentations
2 | Making Slides
3 | Fullscreen vs. Widescreen Aspect Ratio
4 | Typesetting Racket Code in Slideshow
5 | Animations
6 | Legacy Libraries
| Bibliography
| Index

► | 5 | Animations

5.1 | Generating Animated Slides

On this page:

5.1 Generating Animated Slides
play
play-n
animate-slide
current-play-steps

top contents ← prev up next →

## 5 Animations🔗ℹ

(require slideshow/play) | package: slideshow-lib

The slideshow/play module provides tools for generating animations as multiple, automatically advanced slides.

Many of the tools are based on a function that takes a number between 0.0 and 1.0 inclusive and produces a pict. The pict produced for the input 0.0 is the starting image of the animation, and the pict produced for 1.0 is the ending image, while intermediate values produced intermediate images. For example,

> (lambda (n)
> (cellophane (t "Hello") n))

corresponds to an animation that fades in the word “Hello.”

### 5.1 Generating Animated Slides🔗ℹ

> > procedure
> > (play |  | gen |  |  |  |
> > | [ | #:steps steps |  |  |  |
> > |  | #:delay delay-secs |  |  |  |
> > |  | #:skip-first? skip-first? |  |  |  |
> > |  | #:title title |  |  |  |
> > |  | #:name name |  |  |  |
> > |  | #:aspect aspect |  |  |  |
> > |  | #:comment comment |  |  |  |
> > |  | #:layout layout]) |  | → |  | void?
> gen : ((real-in 0.0 1.0) . -> . pict?)
> steps : exact-positive-integer? = (current-play-steps)
> delay-secs : real? = 0.05
> skip-first? : any/c = #f
> | title |  | : |  |
> (or/c string? pict? #f
> ((real-in 0.0 1.0) . -> . (or/c string? pict? #f)))
> |  |  | = |  | #f
> | name |  | : |  |
> (or/c string? #f
> ((real-in 0.0 1.0) . -> . (or/c string? #f)))
> |  |  | = |  | title
> aspect : aspect? = #f
> comment : (or/c comment? #f) = #f
> layout : (or/c 'auto 'center 'top 'tall) = 'auto

Generates steps+1 slides by calling gen on equally-spaced values from 0.0 (inclusive) to 1.0 (exclusive). Except for the first of the slides, each slide has a timeout of delay-secs, so that the next slide appears automatically.

Normally, play is called via play-n, which effectively calls gen on 1.0 without a timeout to complete the animation and stop the auto-advance of slides. The play-n function also manages with multi-step animations.

If skip-first? is #f, then one fewer slide is generated, because gen is not called on 0.0.

The title, name, aspect, and layout arguments are passed on to slide, at least when title and/or name are not functions. When title or name is a function, the function is applied to the value used to produce the slide content, and the resulting title or name is passed on to slide.

The comment argument is used like a comment argument to slide.

In condensed mode (i.e., when condense? is #t), any slide that would be registered with a timeout is instead skipped.

Changed in version 1.7 of package slideshow-lib: Added the aspect argument.

> > procedure
> > (play-n |  | gen* |  |  |  |
> > | [ | #:steps steps |  |  |  |
> > |  | #:delay delay-secs |  |  |  |
> > |  | #:skip-first? skip-first? |  |  |  |
> > |  | #:skip-last? skip-last? |  |  |  |
> > |  | #:title title |  |  |  |
> > |  | #:name name |  |  |  |
> > |  | #:aspect aspect |  |  |  |
> > |  | #:comments comment |  |  |  |
> > |  | #:layout layout]) |  | → |  | void?
> | gen* |  | : |  |
> (and/c (unconstrained-domain-> pict?)
> (λ (x) (number? (procedure-arity x))))
> | steps |  | : |  |
> (list*of exact-positive-integer?
> (or/c exact-positive-integer? '()))
> |  |  | = |  | (current-play-steps)
> delay-secs : real? = 0.05
> skip-first? : any/c = #f
> skip-last? : any/c = #f
> | title |  | : |  |
> (or/c string? pict? #f
> ((real-in 0.0 1.0) . -> . (or/c string? pict? #f)))
> |  |  | = |  | #f
> | name |  | : |  |
> (or/c string? #f
> ((real-in 0.0 1.0) . -> . (or/c string? #f)))
> |  |  | = |  | title
> aspect : aspect? = #f
> comment : (list*of comment? (or/c comment? #f '())) = #f
> layout : (or/c 'auto 'center 'top 'tall) = 'auto

Generates a sequence of slides by calling gen* with, for each of its arguments, numbers from 0.0 to 1.0. If gen* accepts n arguments, then result is a sequence of animations with a pause (i.e., not auto-advanced) between each of n segments.

If gen* accepts a single argument, then play-n is like play, except that gen* is also called with 1.0 to generate a slide with no timeout. If gen* accepts multiple arguments, then slides are generated by calling gen* with the first argument varying from 0.0 to 1.0 while all other arguments are 0.0. Then, the first argument is held at 1.0 while the second argument varies from 0.0 to 1.0, and so on.

For example,

> (play-n
> (lambda (n1 n2)
> (cellophane (t "Hello")
> (* n1 (- 1.0 n2)))))

generates an animation to fade in the word “Hello,” and then pauses for a manual advance, and then fades “Hello” back out.

If skip-first? is #t, then the very first slide of the sequence is skipped. Similarly, if skip-last? is #t, then the last slide of the sequence is skipped.

The steps argument controls how many steps happen in each phase on the animation. If it is a number, then that number is used for each phase. If it is a pair of two numbers, then the first number is used for the first phase, and the second number is used for the rest of the phases. Similarly, if it is (cons num_1 (cons num_2 num_3)), num_1 and num_2 are used for the first two phases and num_3 is used for the rest.

The elements of the comment argument are used like the steps argument, except passed as comments instead of used as step counts.

The delay-secs, title, name, aspect, and layout arguments are passed on to play for each of the n segments of animation.

Changed in version 1.7 of package slideshow-lib: Added the aspect argument.

> procedure (animate-slide element ...)
> → (() (listof (real-in 0.0 1.0)) . ->* . pict?)
> | element |  | : |  |
> (flat-rec-contract elem/c
> (or/c pict? 'next 'alts
> (listof (listof elem/c))))

Accepts slide content similar to slide with 'next and 'alts and produces a procedure suitable for use with play-n. The result is similar to using slide, but with fades for 'next and 'alts transitions (to better fit the style, perhaps, of surrounding animations).

> parameter (current-play-steps) → exact-positive-integer?
> (current-play-steps n) → void?
> n : exact-positive-integer?

A parameter that determines the default number of steps used for a slide animation. The parameter’s initial value is 10.

Added in version 1.6 of package slideshow-lib.

top contents ← prev up next →