On this page:
blur
shadow
shadow-frame
8.12

10 Shadows🔗ℹ

 (require pict/shadow) package: pict-lib

These pict transformations add shadows or blurring in various shapes and forms.

procedure

(blur p h-radius [v-radius])  pict?

  p : pict?
  h-radius : (and/c real? (not/c negative?))
  v-radius : (and/c real? (not/c negative?)) = h-radius
Blurs p using an iterated box blur that approximates a gaussian blur. The h-radius and v-radius arguments control the strength of the horizontal and vertical components of the blur, respectively. They are given in terms of pict units, which may not directly correspond to screen pixels.

The blur function takes work proportional to

(* (pict-width p) (pict-height p))

but it may be sped up by a factor of up to (processor-count) due to the use of futures.

Examples:
> (blur (text "blur" null 40) 5)

image

> (blur (text "more blur" null 40) 10)

image

> (blur (text "much blur" null 40) 20)

image

> (blur (text "horiz. blur" null 40) 10 0)

image

The resulting pict has the same bounding box as p, so when picts are automatically clipped (as in Scribble documents), the pict should be inset by the blur radius.

Example:
> (inset (blur (text "more blur" null 40) 10) 10)

image

Added in version 1.4 of package pict-lib.

procedure

(shadow p    
  radius    
  [dx    
  dy    
  #:color color    
  #:shadow-color shadow-color])  pict?
  p : pict?
  radius : (and/c real? (not/c negative?))
  dx : real? = 0
  dy : real? = dx
  color : (or/c #f string? (is-a?/c color%)) = #f
  shadow-color : (or/c #f string? (is-a?/c color%)) = #f
Creates a shadow effect by superimposing p over a blurred version of p. The shadow is offset from p by (dx, dy) units.

If color is not #f, the foreground part is (colorize p color); otherwise it is just p. If shadow-color is not #f, the shadow part is produced by blurring (colorize p shadow-color); otherwise it is produced by blurring p.

The resulting pict has the same bounding box as p.

Examples:
> (inset (shadow (text "shadow" null 50) 10) 10)

image

> (inset (shadow (text "shadow" null 50) 10 5) 10)

image

> (inset (shadow (text "shadow" null 50)
                 5 0 2 #:color "white" #:shadow-color "red")
         10)

image

Added in version 1.4 of package pict-lib.

procedure

(shadow-frame pict 
  ... 
  [#:sep separation 
  #:margin margin 
  #:background-color bg-color 
  #:frame-color frame-color 
  #:frame-line-width frame-line-width 
  #:shadow-side-length shadow-side-length 
  #:shadow-top-y-offset shadow-top-y-offset 
  #:shadow-bottom-y-offset shadow-bottom-y-offset 
  #:shadow-descent shadow-descent 
  #:shadow-alpha-factor shadow-alpha-factor 
  #:blur blur-radius]) 
  pict?
  pict : pict?
  separation : real? = 5
  margin : real? = 20
  bg-color : (or/c string? (is-a?/c color%)) = "white"
  frame-color : (or/c string? (is-a?/c color%)) = "gray"
  frame-line-width : (or/c real? #f 'no-frame) = 0
  shadow-side-length : real? = 4
  shadow-top-y-offset : real? = 10
  shadow-bottom-y-offset : real? = 4
  shadow-descent : (and/c real? (not/c negative?)) = 40
  shadow-alpha-factor : real? = 3/4
  blur-radius : (and/c real? (not/c negative?)) = 20
Surrounds the picts with a rectangular frame that casts a symmetric “curled paper” shadow.

The picts are vertically appended with separation space between them. They are placed on a rectangular background of solid bg-color with margin space on all sides. A frame of frame-color and frame-line-width is added around the rectangle, unless frame-line-width is 'no-frame. The rectangle casts a shadow that extends shadow-side-length to the left and right, starts shadow-top-y-offset below the top of the rectangle and extends to shadow-bottom-y-offset below the bottom of the rectangle in the center and an additional shadow-descent below that on the sides. The shadow is painted using a linear gradient; shadow-alpha-factor determines its density at the center. Finally, the shadow is blurred by blur-radius; all previous measurements are pre-blur measurements.

Example:
> (shadow-frame (text "text in a nifty frame" null 60))

image

Added in version 1.4 of package pict-lib.