4 Pict Drawing Adjusters
procedure
pict : pict-convertible? factor : real? (scale pict w-factor h-factor) → pict? pict : pict-convertible? w-factor : real? h-factor : real?
The drawing is scaled by adjusting the destination dc<%>’s scale while drawing the original pict.
> (filled-rectangle 40 40)
> (scale (filled-rectangle 40 40) 1.5)
> (scale (filled-rectangle 40 40) 2 1.5)
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
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.
> (define rect (colorize (filled-rectangle 40 40) "olive")) > rect
> (scale-to-fit rect (disk 60))
> (scale-to-fit rect 80 30 #:mode 'preserve)
> (frame (scale-to-fit rect 80 30 #:mode 'inset))
> (scale-to-fit rect 80 30 #:mode 'preserve/max)
> (cc-superimpose (blank 100 100) (frame (scale-to-fit rect 80 30 #:mode 'inset/max)))
> (scale-to-fit rect 80 30 #:mode 'distort)
Changed in version 1.4 of package pict-lib: Added #:mode argument.
procedure
pict : pict-convertible? theta : real?
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.
> (rotate (colorize (filled-rectangle 30 30) "chartreuse") (/ pi 3))
procedure
pict : pict-convertible? x-shear : number? y-shear : number?
> (define sqr (colorize (filled-rectangle 40 20 #:draw-border? #t #:color "purple") "black")) > (shear sqr 0 0.3)
> (shear sqr -0.5 0)
> (shear sqr -0.5 0.3)
Added in version 1.8 of package pict-lib.
procedure
pict : pict-convertible?
procedure
w : (or/c real? #f) pict : pict-convertible?
procedure
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?
> (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))))))
procedure
pict : pict-convertible?
color :
(or/c string? (is-a?/c color%) (list/c byte? byte? byte?))
> (colorize (disk 40) "lavender")
> (colorize (filled-rectangle 40 40) (list 255 153 85))
> (colorize (arrow 40 0) (make-color 170 180 120))
procedure
(cellophane pict opacity) → pict?
pict : pict-convertible? opacity : (real-in 0 1)
> (cc-superimpose (filled-rectangle 70 45 #:color "darkcyan") (cellophane (disk 40) 0.2))
> (cc-superimpose (filled-rectangle 70 45 #:color "darkcyan") (cellophane (disk 40) 0.8))
procedure
(clip pict) → pict
pict : pict-convertible?
> (define shape (inset (colorize (filled-rectangle 40 40) "thistle") -10)) > shape
> (clip shape)
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?
> (filled-rectangle 40 40 #:color "forestgreen")
> (inset/clip (filled-rectangle 40 40 #:color "forestgreen") -10)
> (inset/clip (filled-rectangle 40 40 #:color "forestgreen") -10 -5)
> (inset/clip (filled-rectangle 40 40 #:color "forestgreen") -2 -4 -8 -16)
syntax
(scale/improve-new-text pict-expr scale-expr)
(scale/improve-new-text pict-expr x-scale-expr y-scale-expr)
> (text "Hello World" null 25)
> (scale/improve-new-text (text "Hello World" null 25) 2)
> (scale (text "Hello World" null 25) 2)
parameter
(black-and-white on?) → void? on? : any/c
> (colorize (disk 40) "seagreen")
> (parameterize ([black-and-white #t]) (colorize (disk 40) "seagreen"))
procedure
pict : pict-convertible?
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.