Pict Abbrevs
revolution
real%
nonnegative-real?
pict-color/  c
pict-color->color%
rgb-triplet/  c
color%-update-alpha
rgb-triplet->color%
hex-triplet->color%
pict-bbox-sup
pict-bbox-sup*
max*
min*
rule
string->color%
save-pict
add-rectangle-background
add-rounded-border
add-spotlight-background
1 Slideshow Abbrevs
slide-assembler/  c
slide-assembler/  background
pixels->w%
pixels->h%
w%->pixels
h%->pixels
text/  color
at-underline
at-leftline
make-underline
make-leftline
make-highlight*
highlight-pen-color
highlight-brush-color
2 raco pict
7.1

Pict Abbrevs

The pict-abbrevs module exports the following bindings and does not depend on racket/gui/base.

Changed in version 0.3 of package pict-abbrevs: The pict-abbrevs module no longer reprovides pict-abbrevs/slideshow, and consequently no longer depends on racket/gui/base.

value

revolution : real?

Equal to (* 2 pi), or the tau constant. Useful for rotating picts.

If the name revolution is too long, then do (require (rename-in pict-abbrevs [revolution turn])).

Examples:
> (arrowhead 30 (*   0 revolution))

image

> (arrowhead 30 (* 1/4 revolution))

image

> (arrowhead 30 (* 1/2 revolution))

image

contract

real% : flat-contract?

Same as (between/c 0 1).

Same as (>=/c 0).

Examples:

contract

pict-color/c : (-> any/c boolean?)

Flat contract for the kinds of values that pict functions can usually interpret as colors.

procedure

(pict-color->color% pc #:default default)  (is-a?/c color%)

  pc : pict-color/c
  default : pict-color/c
Creates a color% object. If pc and default are #false, returns (string->color% "white").

Examples:
> (pict-color->color% "blue")

(object:color% ...)

> (pict-color->color% #f)

(object:color% ...)

contract

rgb-triplet/c : (-> any/c boolean?)

Flat contract for an RBG triplet. See also: Plot Utilities.

procedure

(color%-update-alpha c a)  (is-a?/c color%)

  c : (is-a?/c color%)
  a : (real-in 0 1)

Examples:
> (define red (string->color% "red"))
> (disk 20 #:color red)

image

> (disk 20 #:color (color%-update-alpha red 0.3))

image

procedure

(rgb-triplet->color% c)  (is-a?/c color%)

  c : rgb-triplet/c
Converts an RGB triplet to a color object.

procedure

(hex-triplet->color% n)  (is-a?/c color%)

  n : (integer-in 0 16777215)
Converts a Hex Code RGB to a color object. Expects inputs between #x000000 and #xffffff.

procedure

(pict-bbox-sup p ...)  (listof pict?)

  p : pict?

procedure

(pict-bbox-sup* p*)  (listof pict?)

  p* : (listof pict?)
Returns a list of picts with identical width and height. The new picts may be old picts superimposed upon a blank background.

Example:
> (map frame (pict-bbox-sup (disk 10) (disk 20) (disk 5)))

'(image image image)

procedure

(max* r*)  real?

  r* : (listof real?)
Similar to max but expects a list of numbers. Raises an exn:fail:contract? error when given an empty list.

Example:
> (max* '(8 6 7))

8

procedure

(min* r*)  real?

  r* : (listof real?)
Similar to min but expects a list of numbers. Raises an exn:fail:contract? error when given an empty list.

Example:
> (max* '(8 6 7))

8

procedure

(rule w h [#:color c])  pict?

  w : real?
  h : real?
  c : pict-color/c = "black"
Returns a filled-rectangle with the given width, height, and color.

Examples:
> (rule 20 2)

image

> (rule 1 10)

image

> (rule 8 8)

image

procedure

(string->color% str)  (is-a?/c color%)

  str : string?
Converts a string to a color object.

procedure

(save-pict p ps [kind])  boolean?

  p : pict?
  ps : path-string?
  kind : (or/c 'png 'jpeg 'xbm 'xpm 'bmp) = 'png
Exports the given pict to the file ps, using kind to determine the output format.

procedure

(add-rectangle-background pp    
  [#:radius radius    
  #:color color    
  #:draw-border? draw-border?    
  #:x-margin x-margin    
  #:y-margin y-margin])  pict?
  pp : pict?
  radius : real? = 10
  color : pict-color/c = "white"
  draw-border? : boolean? = #false
  x-margin : real? = 0
  y-margin : real? = 0
Add a rectangle behind a pict.

Example:
> (add-rectangle-background (standard-fish 100 50) #:color "bisque")

image

procedure

(add-rounded-border pp    
  [#:radius radius    
  #:background-color bg-color    
  #:frame-width frame-width    
  #:frame-color frame-color    
  #:x-margin x-margin    
  #:y-margin y-margin])  pict?
  pp : pict?
  radius : real? = 10
  bg-color : pict-color/c = "white"
  frame-width : real? = 1
  frame-color : pict-color/c = "black"
  x-margin : real? = 0
  y-margin : real? = 0
Add a bordered rectangle behind a pict.

Example:
> (add-rounded-border (standard-fish 100 50) #:x-margin 20 #:y-margin 30)

image

procedure

(add-spotlight-background pp    
  [#:blur blur    
  #:border-color border-color    
  #:color color    
  #:border-width border-width    
  #:x-margin x-margin    
  #:y-margin y-margin])  pict?
  pp : pict?
  blur : (or/c #f real?) = 15
  border-color : pict-color/c = "plum"
  color : pict-color/c = border-color
  border-width : real? = 10
  x-margin : real? = 40
  y-margin : real? = 40
Superimposes the given pict on a blurred ellipse.

Examples:
> (add-spotlight-background (jack-o-lantern 80))

image

> (add-spotlight-background (jack-o-lantern 80)
                            #:border-color "firebrick"
                            #:color (color%-update-alpha (string->color% "white") 0)
                            #:border-width 15
                            #:x-margin 30
                            #:y-margin 5)

image

1 Slideshow Abbrevs

Helpers for working with slideshow or ppict/2. This module depends on racket/gui/base.

contract

slide-assembler/c : chaperone-contract?

Contract for a function that can be used to build slideshow slides. See also current-slide-assembler.

procedure

(slide-assembler/background base-assembler 
  #:color background-color 
  [#:draw-border? draw-border? 
  #:border-color border-color 
  #:border-width border-width]) 
  slide-assembler/c
  base-assembler : slide-assembler/c
  background-color : pict-color/c
  draw-border? : boolean? = #false
  border-color : pict-color/c = #false
  border-width : (or/c #f real?) = #false
Returns a slide assembler that: (1) uses the given base-assembler to create a pict, and (2) superimposes the pict onto a filled-rectangle that covers the screen. The optional arguments set the style of the background rectangle.

#lang racket/base
(require pict-abbrevs/slideshow slideshow)
 
(parameterize ((current-slide-assembler
                 (slide-assembler/background
                   (current-slide-assembler)
                   #:color "red"))
               (current-font-size 60))
  (slide (t "HOLA")))

procedure

(pixels->w% x)  real%

  x : nonnegative-real?
Converts a pixel distance to a percentage of the max screen width, i.e., (+ (* 2 margin) client-w). Raise an exn:fail:contract? exception if the given distance exceeds the max width.

procedure

(pixels->h% x)  real%

  x : nonnegative-real?
Converts a pixel distance to a percentage of the max screen height, i.e., (+ (* 2 margin) client-h). Raise an exn:fail:contract? exception if the given distance exceeds the max height.

procedure

(w%->pixels w)  nonnegative-real?

  w : real%
Converts a percent to the number of pixels required to cover that percent of client-w.

#lang racket/base
(require slideshow/base pict-abbrevs/slideshow)
 
(w%->pixels 1/10)
(w%->pixels 5/10)
(= client-w (w%->pixels 1))

procedure

(h%->pixels w)  nonnegative-real?

  w : real%
Converts a percent to the number of pixels required to cover that percent of client-h.

procedure

(text/color str c)  pict?

  str : string?
  c : pict-color/c
Draws colored text.

#lang racket/base
(require pict-abbrevs/slideshow)
 
(text/color "red" "red")

procedure

(at-underline pp    
  #:abs-x abs-x    
  #:abs-y abs-y)  refpoint-placer?
  pp : (or/c tag-path? pict-path?)
  abs-x : real?
  abs-y : real?

procedure

(at-leftline pp #:abs-x abs-x #:abs-y abs-y)  refpoint-placer?

  pp : (or/c tag-path? pict-path?)
  abs-x : real?
  abs-y : real?
Returns a placer that places picts to a reference point relative to an existing pict within the base. For at-underline the reference point is the bottom-left. For at-leftline the reference point is the top-left. If given, abs-x and abs-y shift the reference point. See also at-find-pict.

procedure

(make-underline pp    
  #:height height    
  #:color color    
  [#:width width])  pict?
  pp : (or/c pict? real?)
  height : real?
  color : pict-color/c
  width : #f = (or/c #f real?)
Draw a horizontal line wide enough to underline the given pict.

#lang racket/base
(require pict-abbrevs/slideshow ppict/2)
 
(let ((word (text "Word")))
  (ppict-do
    (file-icon 50 40 "bisque")
    #:go (coord 1/2 1/2 'cc)
    word
    #:go (at-underline word)
    (make-underline word)))

procedure

(make-leftline pp    
  #:height height    
  #:color color    
  [#:width width])  pict?
  pp : (or/c pict? real?)
  height : real?
  color : pict-color/c
  width : #f = (or/c #f real?)
Draw a vertical line that is equally high as the given pict.

#lang racket/base
(require pict-abbrevs/slideshow ppict/2)
 
(let ((word (text "Word")))
  (ppict-do
    (file-icon 100 80 "bisque")
    #:go (coord 1/2 1/2 'cc)
    word
    #:go (at-leftline word)
    (make-leftline word #:width 10)))

procedure

(make-highlight* pp tag #:color color)  pict?

  pp : pict?
  tag : symbol?
  color : pict-color/c
Add a background of the given color to all picts tagged (in the sense of tag-pict?) with tag in the scene pp.

#lang racket/base
(require pict-abbrevs/slideshow ppict/2)
 
(ppict-do
  (blank 80 40)
  #:set (for/fold ((acc ppict-do-state))
                  ((i (in-range 8)))
          (ppict-do
            acc
            #:go (coord (/ (* i 10)  80) 9/10)
            (if (even? i)
              (tag-pict (text "X") 'X)
              (tag-pict (text "O") 'O))))
  #:set (make-highlight* ppict-do-state 'X))

value

highlight-pen-color : pict-color/c

Default color for underlines, etc.

value

highlight-brush-color : pict-color/c

Default color for highlights.

2 raco pict

To vertically append image files, or Racket modules:

raco pict vl-append FILE ...

If FILE is a module, then it must contain a submodule named raco-pict that exports an identifier named raco-pict. For example:

#lang racket/base
(module+ raco-pict
  (require pict)
  (define raco-pict (disk 40)))