Drawing Utensils
5.1 Color
5.2 Pen
5.3 Brush
5.4 Font
5.5 Region
5.6 Path
On this page:
Brush
Brush.color
Brush.style
Brush.stipple
Brush.gradient
Brush.Style
Brush.Style.transparent
Brush.Style.solid
Brush.Style.opaque
Brush.Style.hilite
Brush.Style.bdiagonal_  hatch
Brush.Style.crossdiag_  hatch
Brush.Style.fdiagonal_  hatch
Brush.Style.cross_  hatch
Brush.Style.horizontal_  hatch
Brush.Style.vertical_  hatch
Brush.none
Linear  Gradient
Linear  Gradient.line
Linear  Gradient.stops
Radial  Gradient
Radial  Gradient.circles
Radial  Gradient.stops
Brush.handle
Brush.from_  handle
0.45+9.0

5.3 Brush🔗ℹ

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

class

class draw.Brush():

  constructor (

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

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

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

    ~gradient: gradient :: maybe(LinearGradient || RadialGradient) = #false

  )

Creates a brush configuration.

A brush’s ink fills pixels that are bounded by a set of lines or curves. The brush’s style describes the shape that is repeated to fill a region of pixels.

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

If a brush as a gradient, then color, style, and stipple are ignored. With a gradient, for each point in a drawing destination, the gradient associates a color to the point based on starting and ending colors and starting and ending lines (for a linear gradient) or circles (for a radial gradient); a gradient-assigned color is applied for each point that is touched when drawing with the brush.

A brush like an existing one can be constructed using with and the field names color, style, stipple, and/or gradient.

property

property (brush :: draw.Brush).color :: Color

 

property

property (brush :: draw.Brush).style :: Brush.Style

 

property

property (brush :: draw.Brush).stipple :: maybe(Bitmap)

 

property

property (brush :: draw.Brush).gradient

  :: maybe(LinearGradient || RadialGradient)

Properties to access brush components.

Brush-filling 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 #'opaque mode is the same as #'solid for a brush without a stipple, but it causes a monochome stipple to use the destination’s background color in place of white pixels within the stipple. The other modes describe a brush pattern, and they are treated like #'solid for a brush with a stipple.

value

def draw.Brush.none :: Brush

A brush with style #'transparent.

class

class draw.LinearGradient():

  constructor (pt0 :: PointLike,

               pt1 :: PointLike,

               [[stop :: Real.in(0.0, 1.0), color :: Color], ...])

 

property

property (grad :: draw.LinearGradient).line

  :: [Point, _ :: Point]

 

property

property (grad :: draw.LinearGradient).stops

  :: List.of([Real.in(0.0, 1.0), Color])

A linear gradient for a Brush used to fill areas with smooth color transitions.

Color transitions are based on a line, where colors are assigned to stop points along the line, and colors for in-between points are interpolated from the stop-point colors. The color of a point on the gradient’s line is propagated to all points in the drawing context that are touched by a line through the point and perpendicular to the gradient’s line.

The line is from pt0 to pt1. The stops list assigns colors to stop points along the line, where 0.0 corresponds to pt0, 1.0 corresponds to pt1, and numbers in between correspond to points in between.

Elements in stops are implicitly sorted by point (i.e., by the number between 0.0 and 1.0). Order is preserved for multiple elements for the same point, in which case the first element for a given point is treated infinitesimally before the point, and additional elements between the first and last for a stop point are effectively ignored.

class

class draw.RadialGradient():

  constructor ([[pt0 :: PointLike], r0 :: Real],

               [[pt1 :: PointLike], r1 :: Real],

               [[stop :: Real.in(0.0, 1.0), color :: Color], ...])

 

property

property (grad :: draw.RadialGradient).circles

  :: [[PointLike, Real],

      [PointLike, Real]]

 

property

property (grad :: draw.RadialGradient).stops

  :: List.of([Real.in(0.0, 1.0), Color])

A radial gradient for a Brush used to fill areas with smooth color transitions.

Color transitions are based on two circles and the sequence of circles that “morph” from the starting circle to the ending circle. Normally, one of the two circles defining a gradient is nested within the other; in that case, points within the inner circle get the same color as the inner circle’s edge, while points outside the outer circle get the same color as the outer circle’s edge.

Creates a radial gradient with the starting circle as the one with radius r0 centered at pt0 and the ending circle as the one with radius r1 centered at pt1. The stops list assigns colors to circles, where 0.0 corresponds to the starting circle, 1.0 corresponds to the ending circle, and numbers in between correspond to circles in between.

The order of elements within stops and duplicate points are treated in the same way for as LinearGradient.

property

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

 

function

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

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