▼ |  | Pict: Functional Pictures

1 | Pict Datatype
2 | Basic Pict Constructors
3 | Pict Combiners
4 | Pict Drawing Adjusters
5 | Bounding Box Adjusters
6 | Pict Finders
7 | More Pict Constructors
8 | Animation Helpers
9 | Color Helpers
10 | Shadows
11 | Conditional Combinations
12 | Tree Layout
13 | Miscellaneous
14 | Rendering
15 | Conversion to Picts

On this page:

pict-if
pict-cond
pict-case
show
hide

6.8
top ← prev up next →

### 11`` Conditional Combinations

(require pict/conditional) | package: pict-lib

These pict control flow operators decide which pict of several to use. All branches are evaluated; the resulting pict is a combination of the pict chosen by normal conditional flow with ghost applied to all the other picts. The result is a picture large enough to accommodate each alternative, but showing only the chosen one. This is useful for staged slides, as the pict chosen may change with each slide but its size and position will not.

> syntax (pict-if maybe-combine test-expr then-expr else-expr)
> maybe-combine |  | = |  |
> |  | | |  | #:combine combine-expr

Chooses either then-expr or else-expr based on test-expr, similarly to if. Combines the chosen, visible image with the other, invisible image using combine-expr, defaulting to lbl-superimpose.

Example:

> > (let ([f (lambda (x)
> (pict-if x
> (disk 20)
> (disk 40)))])
> (hc-append 10
> (frame (f #t))
> (frame (f #f))))

Added in version 1.4 of package pict-lib.

> syntax (pict-cond maybe-combine [test-expr pict-expr] ...)
> maybe-combine |  | = |  |
> |  | | |  | #:combine combine-expr

Chooses a pict-expr based on the first successful test-expr, similarly to cond. Combines the chosen, visible image with the other, invisible images using combine-expr, defaulting to lbl-superimpose.

Example:

> > (let ([f (lambda (x)
> (pict-cond #:combine cc-superimpose
> [(eq? x 'circle) (circle 20)]
> [(eq? x 'disk) (disk 40)]
> [(eq? x 'text) (text "ok" null 20)]))])
> (hc-append 10
> (frame (f 'circle))
> (frame (f 'disk))
> (frame (f 'text))))

Added in version 1.4 of package pict-lib.

> syntax (pict-case test-expr maybe-combine [literals pict-expr] ...)
> maybe-combine |  | = |  |
> |  | | |  | #:combine combine-expr

Chooses a pict-expr based on test-expr and each list of literals, similarly to case. Combines the chosen, visible image with the other, invisible images using combine-expr, defaulting to lbl-superimpose.

Example:

> > (let ([f (lambda (x)
> (pict-case x
> [(circle) (circle 20)]
> [(disk) (disk 40)]
> [(text) (text "ok" null 20)]))])
> (hc-append 10
> (frame (f 'circle))
> (frame (f 'disk))
> (frame (f 'text))))

Added in version 1.4 of package pict-lib.

> procedure (show pict [show?]) → pict?
> pict : pict?
> show? : any/c = #t
> procedure (hide pict [hide?]) → pict?
> pict : pict?
> hide? : any/c = #t

These functions conditionally show or hide an image, essentially choosing between pict and (ghost pict). The only difference between the two is the default behavior and the opposite meaning of the show? and hide? booleans. Both functions are provided for mnemonic purposes.

Added in version 1.4 of package pict-lib.

top ← prev up next →