On this page:
scale
flip-x
flip-y
scale-to-fit
rotate
shear
translate
ghost
linewidth
linestyle
colorize
cellophane
clip
inset/  clip
scale/  improve-new-text
black-and-white
freeze

4 Pict Drawing Adjusters🔗ℹ

procedure

(scale pict factor)  pict?

  pict : pict-convertible?
  factor : real?
(scale pict w-factor h-factor)  pict?
  pict : pict-convertible?
  w-factor : real?
  h-factor : real?
Scales a pict drawing, as well as its bounding box, by multiplying it current size by factor (if two arguments are supplied) or by multiplying the current width by w-factor and current height by h-factor (if three arguments are supplied).

The drawing is scaled by adjusting the destination dc<%>’s scale while drawing the original pict.

Examples:
> (filled-rectangle 40 40)

image

> (scale (filled-rectangle 40 40) 1.5)

image

> (scale (filled-rectangle 40 40) 2 1.5)

image

procedure

(flip-x pict)  pict?

  pict : pict-convertible?
(flip-y pict)  pict?
  pict : pict-convertible?
Flips a pict drawing horizontally or vertically.

Examples:
> (standard-fish 100 50)

image

> (flip-x (standard-fish 100 50))

image

> (flip-x (flip-x (standard-fish 100 50)))

image

> (flip-y (standard-fish 100 50))

image

> (flip-y (flip-y (standard-fish 100 50)))

image

> (flip-y (flip-x (standard-fish 100 50)))

image

> (flip-x (flip-y (standard-fish 100 50)))

image

procedure

(scale-to-fit pict size-pict [#:mode mode])  pict?

  pict : pict-convertible?
  size-pict : pict-convertible?
  mode : 
(or/c 'preserve 'inset
      'preserve/max 'inset/max
      'distort)
 = 'preserve
(scale-to-fit pict width height [#:mode mode])  pict?
  pict : pict-convertible?
  width : real?
  height : real?
  mode : 
(or/c 'preserve 'inset
      'preserve/max 'inset/max
      'distort)
 = 'preserve
Scales pict so that it fits within the bounding box of size-pict (if two arguments are supplied) or into a box of size width by height (if three arguments are supplied).

If mode is 'preserve or 'preserve/max, the width and height are scaled by the same factor so pict’s aspect ratio is preserved. If mode is 'preserve the result’s bounding box will not be larger than width by height but it may be smaller. When mode is 'preserve/max, the opposite is true; the bounding box will never be smaller, but might be larger.

If mode is 'inset or 'inset/max, the aspect ratio is preserved as with 'preserve and 'preserve/max, but the resulting pict is centered on a bounding box of exactly width by height.

If mode is 'distort, the width and height are scaled separately.

Examples:
> (define rect (colorize (filled-rectangle 40 40) "olive"))
> rect

image

> (scale-to-fit rect (disk 60))

image

> (scale-to-fit rect 80 30 #:mode 'preserve)

image

> (frame (scale-to-fit rect 80 30 #:mode 'inset))

image

> (scale-to-fit rect 80 30 #:mode 'preserve/max)

image

> (cc-superimpose (blank 100 100)
                  (frame (scale-to-fit rect 80 30 #:mode 'inset/max)))

image

> (scale-to-fit rect 80 30 #:mode 'distort)

image

Changed in version 1.4 of package pict-lib: Added #:mode argument.

procedure

(rotate pict theta)  pict?

  pict : pict-convertible?
  theta : real?
Rotates a pict’s drawing by theta radians counter-clockwise.

The bounding box of the resulting pict is the box encloses the rotated corners of pict (which inflates the area of the bounding box, unless theta is a multiple of half of pi). The ascent and descent lines of the result’s bounding box are the horizontal lines that bisect the rotated original lines; if the ascent line drops below the descent line, the two lines are flipped.

Examples:
> (rotate (colorize (filled-rectangle 30 30)
                    "chartreuse")
          (/ pi 3))

image

> (explain (rotate tt 0))

image

> (explain (rotate tt (/ pi 2)))

image

> (explain (rotate tt pi))

image

procedure

(shear pict x-shear y-shear)  pict?

  pict : pict-convertible?
  x-shear : number?
  y-shear : number?
Shear’s the pict by a factor of x-shear along the x-axis and by a factor of y-shear along the y-axis. The bounding box is inflated to contain the result. The result’s ascent and descent are the same as pict’s.

Examples:
> (define sqr
    (colorize (filled-rectangle 40 20 #:draw-border? #t #:color "purple")
              "black"))
> (shear sqr 0 0.3)

image

> (shear sqr -0.5 0)

image

> (shear sqr -0.5 0.3)

image

Added in version 1.8 of package pict-lib.

procedure

(translate pict dx dy [#:extend-bb? bb?])  pict?

  pict : pict-convertible?
  dx : real?
  dy : real?
  bb? : any/c = #f
Translate the pict by dx and dy. If bb? is not #f then the bounding box is extended to ensure the image fits.

Examples:
> (explain (translate tt -3 -3))

image

> (explain (translate tt -3 -3 #:extend-bb? #t))

image

> (explain (translate tt 3 3))

image

> (explain (translate tt 3 3 #:extend-bb? #t))

image

Added in version 1.10 of package pict-lib.

procedure

(ghost pict)  pict?

  pict : pict-convertible?
Creates a container picture that doesn’t draw the child picture, but uses the child’s size.

Example:
> (frame (hc-append (ghost (filled-rectangle 30 30))
                    (colorize (disk 30) "turquoise")))

image

procedure

(linewidth w pict)  pict?

  w : (or/c real? #f)
  pict : pict-convertible?
Selects a specific pen width for drawing, which applies to pen drawing for pict that does not already use a specific pen width. A #f value for w makes the pen transparent (in contrast to a zero value, which means “as thin as possible for the target device”).

Examples:
> (linewidth 3 (hline 40 1))

image

> (linewidth 5 (hline 40 1))

image

procedure

(linestyle style pict)  pict?

  style : 
(or/c 'transparent 'solid 'xor 'hilite
      'dot 'long-dash 'short-dash 'dot-dash
      'xor-dot 'xor-long-dash 'xor-short-dash
      'xor-dot-dash)
  pict : pict-convertible?
Selects a specific pen style for drawing, which applies to pen drawing for pict that does not already use a specific pen style.

Examples:
> (define styles
    '(transparent solid xor hilite dot long-dash short-dash
      dot-dash xor-dot xor-long-dash xor-short-dash xor-dot-dash))
> (apply ht-append
         10
         (for/list ([style (in-list styles)])
           (vc-append 5
             (text (symbol->string style))
             (linewidth 3 (linestyle style (hline 40 1))))))

image

procedure

(colorize pict color)  pict?

  pict : pict-convertible?
  color : 
(or/c string? (is-a?/c color%)
      (list/c byte? byte? byte?))
Selects a specific color drawing, which applies to drawing in pict that does not already use a specific color. The black-and-white parameter causes all non-white colors to be converted to black.

Examples:
> (colorize (disk 40) "lavender")

image

> (colorize (filled-rectangle 40 40)
            (list 255 153 85))

image

> (colorize (arrow 40 0)
            (make-color 170 180 120))

image

procedure

(cellophane pict opacity)  pict?

  pict : pict-convertible?
  opacity : (real-in 0 1)
Makes the given pict semi-transparent, where an opacity of 0 is fully transparent, and an opacity of 1 is fully opaque. See set-alpha for information about the contexts and cases when semi-transparent drawing works.

Examples:
> (cc-superimpose (filled-rectangle 70 45 #:color "darkcyan")
                  (cellophane (disk 40) 0.2))

image

> (cc-superimpose (filled-rectangle 70 45 #:color "darkcyan")
                  (cellophane (disk 40) 0.8))

image

procedure

(clip pict)  pict

  pict : pict-convertible?
Clips a pict’s drawing to its bounding box.

Examples:
> (define shape
    (inset (colorize (filled-rectangle 40 40) "thistle") -10))
> shape

image

> (clip shape)

image

procedure

(inset/clip pict amt)  pict?

  pict : pict-convertible?
  amt : real?
(inset/clip pict h-amt v-amt)  pict?
  pict : pict-convertible?
  h-amt : real?
  v-amt : real?
(inset/clip pict l-amt t-amt r-amt b-amt)  pict?
  pict : pict-convertible?
  l-amt : real?
  t-amt : real?
  r-amt : real?
  b-amt : real?
Insets and clips the pict’s drawing to its bounding box. Usually, the inset amounts are negative.

Examples:
> (filled-rectangle 40 40 #:color "forestgreen")

image

> (inset/clip (filled-rectangle 40 40 #:color "forestgreen") -10)

image

> (inset/clip (filled-rectangle 40 40 #:color "forestgreen")
              -10 -5)

image

> (inset/clip (filled-rectangle 40 40 #:color "forestgreen")
              -2 -4 -8 -16)

image

syntax

(scale/improve-new-text pict-expr scale-expr)

(scale/improve-new-text pict-expr x-scale-expr y-scale-expr)
Like the scale procedure, but also sets current-expected-text-scale while evaluating pict-expr.

Examples:
> (text "Hello World" null 25)

image

> (scale/improve-new-text (text "Hello World" null 25) 2)

image

> (scale (text "Hello World" null 25) 2)

image

parameter

(black-and-white)  boolean?

(black-and-white on?)  void?
  on? : any/c
A parameter that determines whether colorize uses color or black-and-white colors.

Examples:
> (colorize (disk 40) "seagreen")

image

> (parameterize ([black-and-white #t])
    (colorize (disk 40) "seagreen"))

image

procedure

(freeze pict    
  [#:scale scale-amount    
  #:inset inset-amount])  pict?
  pict : pict-convertible?
  scale-amount : real? = 1
  inset-amount : 
(or/c real?
      (list/c real?)
      (list/c real? real?)
      (list/c real? real? real? real?))
 = 0
Creates a bitmap with the same size as pict, draws pict into the bitmap, and then returns a pict that draws with the bitmap.

This has the effect of speeding up subsequent drawing of the pict and also of cropping it to its bounding box. Any sub-picts of pict remain intact within the new pict.

The scale-amount argument controls the size of the bitmap used to render the pict. For example, if scale-amount is 2, then a bitmap that’s twice as wide and twice as tall as the pict is used to draw into. Regardless of the value of scale-amount, the result pict’s size is that same as pict’s size.

The inset-amount argument allows freeze to save more of the area that the pict draws in, which is useful when a pict draws outside of its bounding box. The values are used as the arguments to inset. As with the scale-amount argument, the size of the resulting pict is the same as the size of the input pict; this argument controls the size of the bitmap.

Examples:
> (define txt
    (colorize (text "Freeze!" null 25) "deepskyblue"))
> (scale txt 2.5)

image

> (scale (freeze txt) 2.5)

image

Changed in version 1.13 of package pict-lib: Added the scale and inset arguments.