Drawing Utensils
5.1 Color
5.2 Pen
5.3 Brush
5.4 Font
5.5 Region
5.6 Path
On this page:
Pen
Pen.color
Pen.width
Pen.style
Pen.cap
Pen.join
Pen.stipple
Pen.Style
Pen.Style.transparent
Pen.Style.solid
Pen.Style.hilite
Pen.Style.dot
Pen.Style.long_  dash
Pen.Style.show_  dash
Pen.Style.dot_  dash
Pen.Style.xor_  dot
Pen.Style.xor_  long_  dot
Pen.Style.xor_  short_  dot
Pen.Style.xor_  dot_  dash
Pen.Cap
Pen.Cap.round
Pen.Cap.projecting
Pen.Cap.butt
Pen.Join
Pen.Join.round
Pen.Join.bevel
Pen.Join.miter
Pen.none
Pen.handle
Pen.from_  handle
0.45+9.1.0.1

5.2 Pen🔗ℹ

A pen is typically installed to a drawing context’s DC.pen property.

class

class draw.Pen():

  constructor (

    ~color: color :: (String || Color) = "Black",

    ~width: width :: Real.in(0, 255) = 1,

    ~cap: cap :: Pen.Cap = #'round,

    ~join: join :: Pen.Join = #'round,

    ~style: style :: Pen.Style = #'solid,

    ~stipple: stipple :: maybe(Bitmap) = #false,

  )

Creates a pen configuration.

A pen’s ink straddles the mathematical line or curve that it draws, so that it spans width/2 drawing units on each side. A width or 0 is treated as a minimal drawin unit for the destination, such as a single pixel for a bitmap destination.

A pen’s cap is used to shape each end of a line or curve, except in the case that multiple lines or curves are joined together. In the latter case, join points are shaped by cap.

A pen’s style determines how it draws along a line or curve. Drawing with a #'transparent pen is the same as not drawing.

If a pen has a stipple bitmap, some styles are ignored (see Pen.Style), and stipple it is used to fill pixels that otherwise would be covered by the pen’s ink. A monochrome stipple takes on color as it is drawn.

A pen like an existing one can be constructed using with and the field names color, width, style, cap, join, and/or stipple.

property

property (pen :: draw.Pen).color :: Color

 

property

property (pen :: draw.Pen).width :: Real.in(0, 255)

 

property

property (pen :: draw.Pen).style :: Pen.Style

 

property

property (pen :: draw.Pen).cap :: Pen.Cap

 

property

property (pen :: draw.Pen).join :: Pen.Join

 

property

property (pen :: draw.Pen).stipple :: maybe(Bitmap)

Properties to access pen components.

Line-drawing modes. The #'transparent mode applies an alpha of 0 to drawing, #'solid applies an alpha of 1.0, and #'hilite applies an alpha of 0.3. The other modes describe a line shape, and they are treated like #'solid for a pen with a stipple.

enumeration

enum draw.Pen.Cap

| round

| projecting

| butt

Line-ending modes; see Pen.

enumeration

enum draw.Pen.Join

| round

| bevel

| miter

Line-joining modes; see Pen.

value

def draw.Pen.none :: Pen

A pen with style #'transparent.

property

property (path :: draw.Pen).handle :: Any

 

function

fun draw.Pen.from_handle(hand :: Any) :: Pen

The Pen.handle property returns a Racket object that corresponds to the pen for use directly with racket/draw. The Pen.from_handle function creates a Pen from such a Racket object.