On this page:
Pict
Static  Pict
nothing
Nothing  Pict
Pict.width
Pict.height
Pict.ascent
Pict.descent
Pict.pad
Pict.drop_  baseline
Pict.drop_  topline
Pict.translate
Pict.scale
Pict.rotate
Pict.shear
Pict.alpha
Pict.hflip
Pict.vflip
Pict.clip
Pict.colorize
Pict.line_  width
Pict.children
Pict.launder
Pict.ghost
Pict.blank
Pict.refocus
Pict.freeze
Pict.paragraph_  end_  bounds
Pict.set_  paragraph_  end_  bounds
Pict.metadata
Pict.set_  metadata
Pict.identity
Pict  Identity
Pict  Identity.description
Pict.set_  description
Pict.description
Pict.draw
Pict.drawer
Static  Pict.handle
Static  Pict.draw_  handle
Pict.from_  handle
Time  Order
Time  Order.before
Time  Order.after
8.16.0.4

2 Pict Objects🔗ℹ

annotation

Pict

 

annotation

StaticPict

The Pict annotation is satisfied by any pict value. The StaticPict annotation is statisfied only by a pict that is specifically a static pict.

> rectangle() is_a Pict

#true

> rectangle() is_a StaticPict

#true

> animate(fun (n): rectangle()) is_a StaticPict

#false

value

def nothing :: NothingPict

 

annotation

NothingPict

The nothing pict is a special static pict that is ignored (i.e., as if it is not supplied at all) by pict primitive constructors. The NothingPict annotation is satisfied by only nothing.

> beside(stack(~sep: 5, text("Hello"), nothing, nothing, text("World")),

         stack(~sep: 5, text("Hello"), text("World")))

image

property

property (pict :: Pict).width :: Real

 

property

property (pict :: Pict).height :: Real

 

property

property (pict :: Pict).ascent :: Real

 

property

property (pict :: Pict).descent :: Real

Properties for a pict’s bounding box. See Static Picts for an explanation of bounding boxes.

> def p = stack(text("Hello"), text("Pict"), text("World"))

> explain_bbox(p)

image

> p.width

46.0

> p.height

57.0

> p.ascent

15.0

> p.descent

4.0

> explain_bbox(p.pad(-5)).pad(8)

image

method

method (pict :: Pict).pad(

  around :: Real = 0,

  ~horiz: horiz :: Real = around,

  ~vert: vert :: Real = around,

  ~left: left :: Real = horiz,

  ~top: top :: Real = vert,

  ~right: right :: Real = horiz,

  ~bottom: bottom :: Real = vert

) :: Pict

 

method

method (pict :: Pict).drop_baseline(amt :: Real) :: Pict

 

method

method (pict :: Pict).drop_topline(amt :: Real) :: Pict

 

method

method (pict :: Pict).translate(dx :: Real, dy :: Real) :: Pict

Returns a pict that draws the same as pict, but with its bounding box adjusted. The Pict.pad function conceptually adds padding around the outside of a bounding box, shifting it away from the inside of the pict’s drawing; negative padding shifts a bounding box toward the inside. The Pict.drop_baseline and Pict.drop_topline functions adjust the bounding box’s decent (subtracting amt) and ascent (adding amt), respectively. The Pict.translate function shifts drawing relative to its bounding box, which keeps the same width, height, ascent, and descent.

> explain_bbox(text("Hello"))

image

> explain_bbox(text("Hello").pad(5))

image

> explain_bbox(text("Hello").pad(~left: 5, ~right: 10))

image

> explain_bbox(beside(~vert: #'topline,

                      text("Hello").drop_topline(-3),

                      text("World")))

image

> explain_bbox(text("Hello").translate(5, -5))

image

method

method (pict :: Pict).scale(n :: Real) :: Pict

 

method

method (pict :: Pict).scale(horiz :: Real, vert :: Real) :: Pict

Returns a pict that is like pict, but its drawing and bounding box is scaled.

> def p = text("Hello").colorize("firebrick")

> p

image

> p.scale(2)

image

method

method (pict :: Pict).rotate(radians :: Real) :: Pict

Returns a pict that is like pict, but its drawing is rotated, and its bounding box is extended as needed to enclose the rotated bounding box.

> def p = text("Hello").colorize("firebrick")

> p.rotate(math.pi/4)

image

method

method (pict :: Pict).shear(x_factor :: Real,

                            y_factor :: Real) :: Pict

Returns a pict that is like pict, but its drawing is sheared by progressively adjusting the x-position of drawing so that it is shifted by x_factor of the height by the bottom of the bounding box, and by adjusting the y-positio of drawing to shift it by y_factor of the width by the right edge of the bounding box. The bounding box is inflated to contain the result. The result pict’s ascent and descent are the same as pict’s.

> def p = text("Hello").colorize("firebrick")

> p.shear(0.5, 0)

image

> p.shear(0, 0.5)

image

method

method (pict :: Pict).alpha(n :: Real.in(0, 1)) :: Pict

Returns a pict that is like pict, but whose drawing is changed by multiplying n to an inherited alpha adjustment.

> def p = text("Hello").colorize("firebrick")

> p

image

> p.alpha(0.5)

image

> p.alpha(0.25)

image

method

method (pict :: Pict).hflip() :: Pict

 

method

method (pict :: Pict).vflip() :: Pict

Flips a pict horizontally or vertically.

> def p = text("Hello").colorize("firebrick")

> p.hflip()

image

> p.vflip()

image

method

method (pict :: Pict).clip() :: Pict

Returns a pict that is like pict, but whose drawing is confined to its bounding box.

> def p = text("Hello").colorize("firebrick").pad(-5).scale(2)

> rectangle(~around: p).pad(10)

image

> rectangle(~around: p.clip()).pad(10)

image

method

method (pict :: Pict).colorize(c :: Color || String) :: Pict

 

method

method (pict :: Pict).line_width(w :: NonnegReal) :: Pict

Returns a pict that is like pict, but wherever it uses #'inherit for a color or line width, the given color or line width is used, and the resulting pict no longer uses #'inherit or colors or line widths.

> def p = square(~size: 20)

> p

image

> p.colorize("firebrick").line_width(2)

image

> def p = square(~size: 20,

                 ~line_width: 2,

                 ~line: #'inherit,

                 ~fill: "lightblue")

> p

image

> p.colorize("firebrick").line_width(0)

image

property

property (pict :: Pict).children :: List.of(Pict)

Produces the findable children pf pict: a list of component picts that were combined to construct pict. Those picts can be located within pict using a finder.

> def h = text("Hello").colorize("firebrick")

> def w = text("World").colorize("firebrick")

> h.children

[image]

> stack(h, w)

image

> stack(h, w).children

[image, image]

> Find.top_left(w).in(stack(h, w))

0.0

19.0

method

method (pict :: Pict).launder(

  ~rebuild_prompt: rebuild_prompt = #false

) :: Pict

Returns a pict that is the same as pict, but with a fresh identity and hiding the identity of any component inside pict from a finder or the result of the Pict.children property. That is, the result from Pict.launder has no findable children other than itself.

If rebuild_prompt is true, then the result pict also has no replaceable dependencies.

See also Pict Findable and Replaceable Identity and Pict.blank.

> def h = text("Hello")

> def w = text("World")

> def p = stack(h, w)

> Find.top_left(w).in(p)

0.0

19.0

> def q = p.launder()

> Find.top_left(w).in(q)

Find.in: cannot find pict

  pict: Pict("World", 56111980)

  in pict: Pict("stack", "Hello", "World", 56111982)

method

method (pict :: Pict).ghost(do_ghost = #true) :: Pict

Returns a pict that is the same as pict, including the same bounding box and time box, but whose drawing is empty if do_ghost is true. If do_ghost is #false, then pict itself is returned.

The do_ghost argument is intended to help avoid if wrappers, enabling pict.ghost(test) instead of if test | pict.ghost() | pict, where the former works even without having to bind an intermediate variable if pict is replaced with a more complex expression.

See also Pict.blank.

> def p = text("Hello")

> rectangle(~around: p)

image

> rectangle(~around: p.ghost())

image

> rectangle(~around: p.ghost(#false))

image

method

method (pict :: Pict).blank(

  ~rebuild_prompt: rebuild_prompt = #true

) :: Pict

Equivalent to pict.ghost().launder(~rebuild_prompt: rebuild_prompt) where rebuild_prompt defaults to #true, in contrast to the #false default for Pict.launder.

method

method (pict :: Pict).refocus(subpict :: Pict) :: Pict

Returns a pict that is the same as pict, but with a shifted bounding box to match the binding box of subpict within pict.

> def h = text("Hello")

> def p = beside(circle(~size: 20, ~fill: "lightgreen"),

                 stack(h, text("World")),

                 square(~size: 20, ~fill: "lightblue"))

> explain_bbox(p).pad(20)

image

> explain_bbox(p.refocus(h)).pad(20)

image

method

method (pict :: Pict).freeze(~scale: scale :: Real = 2.0) :: Pict

Returns a pict that is like pict, but whose drawing is rendered at the time of the Pict.freeze call to a bitmap, and then the new pict draws by drawing the bitmap. The scale argument determines the scale factor of the bitmap (i.e., the number of pixels per drawing unit).

method

method (pict :: Pict).paragraph_end_bounds()

  :: values(Real, Real, Real, Real, Real, Real)

 

method

method (pict :: Pict).set_paragraph_end_bounds(

  dx :: Real,

  dy :: Real,

  width :: Real,

  height :: Real,

  ascent :: Real,

  descent :: Real

) :: Pict

Gets or sets bounds relative to pict’s bounding box that specify a nested bounding box for composition via beside in #'paragraph attach mode. The results from Pict.paragraph_end_bounds are in the same order as the arguments to Pict.set_paragraph_end_bounds, which describe an offset and a bounding box at that offset.

For most pict constructions, the paragraph-end bounding box will be the same as the pict’s overall bounding box with a zero offset.

Whenever multiple picts are combined using stack or beside, the paragraph-end bounding box of the last pict provided to stack or beside is used for the result pict’s paragraph-end bounds. A beside combination in #'paragraph attach mode will then append relative to that last pict in the composition, instead of to the composition as a whole.

method

method (pict :: Pict).metadata() :: Map

 

method

method (pict :: Pict).set_metadata(metadata :: Map) :: Pict

Gets metadata registered for an immediate pict, or returns a pict that is like pict but with the given metadata.

Unlike epoch-specific metadata added with Pict.epoch_set_metadata, metadata added by Pict.set_metadata is not propagated to new picts that are derived from the returned pict. The Pict.children property of a pict can be used to search the metadata of its component picts.

property

property (pict :: Pict).identity :: PictIdentity

 

class

class PictIdentity():

  ~no_constructor

 

method

method (ident :: PictIdentity).description() :: List.of(String)

 

method

method (pict :: Pict).set_description(desc :: Any) :: Pict

 

method

method (pict :: Pict).description() :: List.of(String)

The Pict.identity property returns an object representing the identity of a pict for the purpose of finding it in other picts. See Pict Findable and Replaceable Identity for more information about pict identity.

An identity has a description that is used by to_string for a pict, which can be helpful for debugging. A pict’s description is normally synthesized automatically, but it can be configured through Pict.set_description. A description provided to Pict.set_description is most useful as a string, another pict’s identity, a list of such values, or #false to suppress a debugging description.

The Pict.description method is a shorthand for getting the description of pict’s identity.

method

method (pict :: Pict).draw(dc :: DC,

                           ~dx: dx :: Real = 0,

                           ~dx: dy :: Real = 0) :: Void

 

method

method (pict :: Pict).drawer()

  :: Function.of_arity(1, ~dx, ~dy)

Draws a pict or returns a function that can be used to draw the pict. Repeatedly using the function produced by Pict.drawer may be faster than repeatedly calling Pict.draw. If pict is animated, then it is drawn the same as pict.snapshot().

> def bm = draw.Bitmap([20, 20], ~backing_scale: 2)

> def p = circle(~size: 20, ~fill: "lightgreen")

> p.draw(bm.make_dc())

> bm.write("circle.png", ~kind: #'png)

property

property (pict :: StaticPict).handle :: Any

 

property

property (pict :: StaticPict).draw_handle :: Any

 

function

fun Pict.from_handle(hand :: Any) :: StaticPict

Converts a rhombus pict to/from a Racket pict.

The StaticPict.draw_handle property returns a Racket pict suitable for drawing directly or embedding in a Racket pict construction. It configures the drawing context with more modern defaults, including drawing in #'smoothed mode.

enumeration

enum TimeOrder:

  before

  after

Options for time directions.