On this page:
blank
rectangle
square
ellipse
circle
triangle
polygon
line
text
bitmap
dc
explain_  bbox
Color  Mode
Color  Mode.inherit
Line  Width
Line  Width.inherit
Auto  Real
Auto  Real.auto
Refocus
Refocus.around
Rounded
Rounded.default
Arc  Direction
Arc  Direction.cw
Arc  Direction.ccw
8.16.0.4

3 Pict Constructors🔗ℹ

function

fun blank(

  size :: Real = 0,

  ~width: width :: Real = size,

  ~height: height :: Real = size,

  ~ascent: ascent :: Real = height,

  ~descent: descent :: Real = 0

) :: StaticPict

Creates a blank static pict with the specified bounding box.

> blank(10)

image

> blank(10).width

10

function

fun rectangle(

  ~around: around :: maybe(Pict) = #false,

  ~width: width :: AutoReal = #'auto,

  ~height: height :: AutoReal = #'auto,

  ~fill: fill :: maybe(ColorMode) = #false,

  ~line: line :: maybe(ColorMode) = !fill && #'inherit,

  ~line_width: line_width :: LineWidth = #'inherit,

  ~rounded: rounded :: maybe(Rounded) = #false,              

  ~order: order :: OverlayOrder = #'front,

  ~refocus: refocus_on :: maybe(Refocus) = #'around,

  ~epoch: epoch_align :: EpochAlignment = #'center,

  ~duration: duration_align :: DurationAlignment = #'sustain

) :: Pict

Creates a pict to draw a rectangle. If an around pict is provided, then it both supplies default width and height values and is overlayed on top of the rectangle image,

The rectangle has an outline if line is not #false, and it is filled in if fill is not #false. If the rectangle has an outline, line_width is used for the outline. A line, fill, or line_width can be #'inherit to indicate that a context-supplied color and line width should be used. See also Pict.colorize and Pict.colorize Pict.line_width.

If rounded is a non-negative number, it is used as the radius of an arc to use for the rectangle’s corners. If rounded is a negative number, it is negated and multiplied by the rectangle’s width and height to get a radius (in each direction) for the rounded corner.

When the refocus_on argument is a pict, then Pict.refocus is used on the resulting pict with refocus_on as the second argument. If refocus_on is #'around and around is not #false, then the pict is refocused on around, and then padded if necessary to make the width and height match width and height.

The epoch_align and duration_align arguments are used only when around is supplied, and they are passed on to overlay to combine a static rectangle pict with around. The order argument is similarly passed along to overlay, where #'front places around in front of the rectangle. If around is #false, the resulting pict is always a static pict.

> rectangle()

image

> rectangle(~fill: "lightblue", ~line: #false)

image

> rectangle(~line: "blue", ~rounded: #'default)

image

> rectangle(~around: text("Hello"), ~fill: "lightgreen")

image

function

fun square(

  ~around: around :: maybe(Pict) = #false,

  ~size: size :: AutoReal = #'auto,

  ~fill: fill :: maybe(ColorMode) = #false,

  ~line: line :: maybe(ColorMode) = !fill && #'inherit,

  ~line_width: line_width :: LineWidth = #'inherit,

  ~rounded: rounded :: maybe(Rounded) = #false,              

  ~order: order :: OverlayOrder = #'front,

  ~refocus: refocus_on :: maybe(Refocus) = #'around,

  ~epoch: epoch_align :: EpochAlignment = #'center,

  ~duration: duration_align :: DurationAlignment = #'sustain

) :: Pict

A shorthand for rectangle where the width and height are specified as size.

> square(~around: text("Hello"), ~fill: "lightgreen")

image

function

fun ellipse(

  ~around: around :: maybe(Pict) = #false,

  ~width: width :: AutoReal = #'auto,

  ~height: height :: AutoReal = #'auto,

  ~arc: arc :: maybe(ArcDirection) = #false,

  ~start: start :: Real = 0,

  ~end: end :: Real = 2 * math.pi,

  ~fill: fill :: maybe(ColorMode) = #false,

  ~line: line :: maybe(ColorMode) = !fill && #'inherit,

  ~line_width: line_width :: LineWidth = #'inherit,

  ~order: order :: OverlayOrder = #'front,

  ~refocus: refocus_on :: maybe(Refocus) = #'around,

  ~epoch: epoch_align :: EpochAlignment = #'center,

  ~duration: duration_align :: DurationAlignment = #'sustain

) :: Pict

Like rectangle, but for an ellipse or arc/wedge. The pict draws an arc or widge if arc is #'cw (clockwise) or #'ccw (counterclockwise).

When around is provided, it determines default width and height values, but since the ellipse fits inside a width by height rectangle, the around pict may extend beyond the ellipse’s edge at the corners.

> ellipse(~around: text("Hello"), ~fill: "lightgreen")

image

function

fun circle(

  ~around: around :: maybe(Pict) = #false,

  ~size: size :: AutoReal = #'auto,

  ~arc: arc :: maybe(ArcDirection) = #false,

  ~start: start :: Real = 0,

  ~end: end :: Real = 2 * math.pi,

  ~fill: fill :: maybe(ColorMode) = #false,

  ~line: line :: maybe(ColorMode) = !fill && #'inherit,

  ~line_width: line_width :: LineWidth = #'inherit,

  ~order: order :: OverlayOrder = #'front,

  ~refocus: refocus_on :: maybe(Refocus) = #'around,

  ~epoch: epoch_align :: EpochAlignment = #'center,

  ~duration: duration_align :: DurationAlignment = #'sustain

) :: Pict

Like square, but a shorthand for ellipse.

> circle(~around: text("Hello"), ~fill: "lightgreen")

image

function

fun triangle(

  ~around: around :: maybe(Pict) = #false,

  ~size: size :: AutoReal = #'auto,

  ~width: width :: AutoReal = size,

  ~height: height :: AutoReal = size,

  ~fill: fill :: maybe(ColorMode) = #false,

  ~line: line :: maybe(ColorMode) = !fill && #'inherit,

  ~line_width: line_width :: LineWidth = #'inherit,

  ~rounded: rounded :: maybe(Rounded) = #false,              

  ~order: order :: OverlayOrder = #'front,

  ~refocus: refocus_on :: maybe(Refocus) = #'around,

  ~epoch: epoch_align :: EpochAlignment = #'center,

  ~duration: duration_align :: DurationAlignment = #'sustain

) :: Pict

Like rectangle, but for an isosceles triangle with a base along the bottom of a rectangle defined by width and height and a vertex at the center of the top of the rectangle. As a shorthand, the size argument can be used as both the width and height.

> triangle(~fill: "orange")

image

> triangle(~fill: "orange").rotate(-1/2 * math.pi)

image

function

fun polygon(

  [pt :: draw.PointLike.to_point, ...],

  ~fill: fill :: maybe(ColorMode) = #false,

  ~line: line :: maybe(ColorMode) = !fill && #'inherit,

  ~line_width: line_width :: LineWidth = #'inherit

) :: Pict

Creates a pict that draws a polygon. The maximum x and y values among the pts determine the resulting pict’s bounding box.

> polygon([[0, 0], [50, 0], [50, 50]], ~fill: "lightgreen")

image

function

fun line(

  ~dx: dx :: Real = 0,

  ~dy: dy :: Real = 0,

  ~line: color :: maybe(ColorMode) = #'inherit,

  ~line_width: width :: LineWidth = #'inherit

) :: Pict

Creates a pict that draws a line from the top-left of the pict. The dx and dy arguments determine both the shape of the line and the width and height of the pict.

> line(~dx: 10, ~line_width: 3)

image

> line(~dy: 10, ~line: "blue", ~line_width: 3)

image

> line(~dx: 10, ~dy: 10)

image

function

fun text(content :: String,

         ~font: font :: draw.Font = draw.Font()) :: Pict

Creates a pict that draws text using font

> text("Hello")

image

> text("Hi!", ~font: draw.Font(~kind: #'roman, ~size: 20, ~style: #'italic))

image

function

fun bitmap(path :: Path || String) :: Pict

Creates a pict that draws a bitmap as loaded from path.

function

fun dc(draw :: (draw.DC, Real, Real) -> ~any,

       ~width: width :: Real,

       ~height: height :: Real,

       ~ascent: ascent :: Real = height,

       ~descent: descent :: Real = 0) :: Pict

Creates a pict with an arbitrary drawing context. The draw function receives a draw.DC, an x-offset, and a y-offset.

> dc(fun (dc :: draw.DC, dx, dy):

       dc.line([dx, dy+10], [dx+20, dy+10])

       dc.line([dx+10, dy], [dx+10, dy+20])

       dc.ellipse([[dx, dy], [21, 21]]),

     ~width: 20,

     ~height: 20)

image

function

fun explain_bbox(

  pic :: Pict,

  ~line: line :: maybe(ColorMode) = "firebrick",

  ~baseline: baseline :: maybe(ColorMode) = "royalblue",

  ~topline: topline :: maybe(ColorMode) = "seagreen",

  ~scale: scale_n :: Real = 3,

  ~line_width: line_width :: LineWidth = 1,

  ~epoch: epoch_align :: EpochAlignment = #'center,

  ~duration: duration_align :: DurationAlignment = #'sustain

) :: Pict

Returns a pict like pict, but the pict’s bounding box is framed in the color line, a baseline showing the bounding box’s descent is draw as a line using the color baseline, and a topline showing the bounding box’s ascent is draw as a line using the color topline. If any line color is #false, then that part is not drawn. The pict is then scaled by scale_n. The bounding box lines use width line_width before scaling.

Note that for a single line of text, the baseline and topline are the same, so only one line will be visible.

The epoch_align and duration_align arguments are used as in rectangle.

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

> explain_bbox(p)

image

enumeration

enum ColorMode:

  ~is_a Color

  ~is_a String

  inherit

A color specification, where #'inherit allows the color to be configured externally, such as through Pict.colorize.

enumeration

enum LineWidth:

  ~is_a Real

  inherit

A line-width specification, where #'inherit allows the color to be configured externally, such as through Pict.line_width.

enumeration

enum AutoReal:

  ~is_a Real

  auto

A dimension with a computed default indicated by #'auto for functions like rectangle.

enumeration

enum Refocus:

  ~is_a Pict

  around

Refocusing options for functions like rectangle.

enumeration

enum Rounded:

  ~is_a Real

  default

Corner-rounding options for rectangle.

enumeration

enum ArcDirection:

  cw

  ccw

Arc directions, clockwise or counterclockwise.