Brush
sealed class Brush
Properties
open val intrinsicSize: Size
Return the intrinsic size of the Brush
. If the there is no intrinsic size (i.e. filling
bounds with an arbitrary color) return Size.Unspecified
. If there is no intrinsic size in a
single dimension, return Size
with Float.NaN
in the desired dimension.
Functions
abstract fun applyTo(size: Size, p: Paint, alpha: Float)
Companion Object
Methods
fun linearGradient(
vararg colorStops: Pair<Float, Color>,
start: Offset = Offset.Zero,
end: Offset = Offset.Infinite,
tileMode: TileMode = TileMode.Clamp,
): Brush
Creates a linear gradient with the provided colors along the given start and end coordinates. The colors are dispersed at the provided offset defined in the colorstop pair.
Brush.linearGradient( 0.0f to Color.Red, 0.3f to Color.Green, 1.0f to Color.Blue, start = Offset(0.0f, 50.0f), end = Offset(0.0f, 100.0f)
)
Parameters
colorStops | Colors and their offset in the gradient area |
start | Starting position of the linear gradient. This can be set to Offset.Zero to position at the far left and top of the drawing area |
end | Ending position of the linear gradient. This can be set to Offset.Infinite to position at the far right and bottom of the drawing area |
tileMode | Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels |
fun linearGradient(
colors: List<Color>,
start: Offset = Offset.Zero,
end: Offset = Offset.Infinite,
tileMode: TileMode = TileMode.Clamp,
): Brush
Creates a linear gradient with the provided colors along the given start and end coordinates. The colors are
Brush.linearGradient( listOf(Color.Red, Color.Green, Color.Blue), start = Offset(0.0f, 50.0f), end = Offset(0.0f, 100.0f)
)
Parameters
colors | Colors to be rendered as part of the gradient |
start | Starting position of the linear gradient. This can be set to Offset.Zero to position at the far left and top of the drawing area |
end | Ending position of the linear gradient. This can be set to Offset.Infinite to position at the far right and bottom of the drawing area |
tileMode | Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels |
fun horizontalGradient(
colors: List<Color>,
startX: Float = 0.0f,
endX: Float = Float.POSITIVE_INFINITY,
tileMode: TileMode = TileMode.Clamp,
): Brush
Creates a horizontal gradient with the given colors evenly dispersed within the gradient
Ex:
Brush.horizontalGradient( listOf(Color.Red, Color.Green, Color.Blue), startX = 10.0f, endX = 20.0f
)
Parameters
colors | colors Colors to be rendered as part of the gradient |
startX | Starting x position of the horizontal gradient. Defaults to 0 which represents the left of the drawing area |
endX | Ending x position of the horizontal gradient. Defaults to Float.POSITIVE_INFINITY which indicates the right of the specified drawing area |
tileMode | Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels |
fun horizontalGradient(
vararg colorStops: Pair<Float, Color>,
startX: Float = 0.0f,
endX: Float = Float.POSITIVE_INFINITY,
tileMode: TileMode = TileMode.Clamp,
): Brush
Creates a horizontal gradient with the given colors dispersed at the provided offset defined in the colorstop pair.
Ex:
Brush.horizontalGradient( 0.0f to Color.Red, 0.3f to Color.Green, 1.0f to Color.Blue, startX = 0.0f, endX = 100.0f
)
Parameters
colorStops | Colors and offsets to determine how the colors are dispersed throughout the vertical gradient |
startX | Starting x position of the horizontal gradient. Defaults to 0 which represents the left of the drawing area |
endX | Ending x position of the horizontal gradient. Defaults to Float.POSITIVE_INFINITY which indicates the right of the specified drawing area |
tileMode | Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels |
fun verticalGradient(
colors: List<Color>,
startY: Float = 0.0f,
endY: Float = Float.POSITIVE_INFINITY,
tileMode: TileMode = TileMode.Clamp,
): Brush
Creates a vertical gradient with the given colors evenly dispersed within the gradient Ex:
Brush.verticalGradient( listOf(Color.Red, Color.Green, Color.Blue), startY = 0.0f, endY = 100.0f
)
Parameters
colors | colors Colors to be rendered as part of the gradient |
startY | Starting y position of the vertical gradient. Defaults to 0 which represents the top of the drawing area |
endY | Ending y position of the vertical gradient. Defaults to Float.POSITIVE_INFINITY which indicates the bottom of the specified drawing area |
tileMode | Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels |
fun verticalGradient(
vararg colorStops: Pair<Float, Color>,
startY: Float = 0f,
endY: Float = Float.POSITIVE_INFINITY,
tileMode: TileMode = TileMode.Clamp,
): Brush
Creates a vertical gradient with the given colors at the provided offset defined in the
Pair<Float, Color>
Ex:
Brush.verticalGradient( 0.1f to Color.Red, 0.3f to Color.Green, 0.5f to Color.Blue, startY = 0.0f, endY = 100.0f
)
Parameters
colorStops | Colors and offsets to determine how the colors are dispersed throughout the vertical gradient |
startY | Starting y position of the vertical gradient. Defaults to 0 which represents the top of the drawing area |
endY | Ending y position of the vertical gradient. Defaults to Float.POSITIVE_INFINITY which indicates the bottom of the specified drawing area |
tileMode | Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels |
fun radialGradient(
vararg colorStops: Pair<Float, Color>,
center: Offset = Offset.Unspecified,
radius: Float = Float.POSITIVE_INFINITY,
tileMode: TileMode = TileMode.Clamp,
): Brush
Creates a radial gradient with the given colors at the provided offset defined in the colorstop pair.
Brush.radialGradient( 0.0f to Color.Red, 0.3f to Color.Green, 1.0f to Color.Blue, center = Offset(side1 / 2.0f, side2 / 2.0f), radius = side1 / 2.0f, tileMode = TileMode.Repeated
)
Parameters
colorStops | Colors and offsets to determine how the colors are dispersed throughout the radial gradient |
center | Center position of the radial gradient circle. If this is set to Offset.Unspecified then the center of the drawing area is used as the center for the radial gradient. Float.POSITIVE_INFINITY can be used for either Offset.x or Offset.y to indicate the far right or far bottom of the drawing area respectively. |
radius | Radius for the radial gradient. Defaults to positive infinity to indicate the largest radius that can fit within the bounds of the drawing area |
tileMode | Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels |
fun radialGradient(
colors: List<Color>,
center: Offset = Offset.Unspecified,
radius: Float = Float.POSITIVE_INFINITY,
tileMode: TileMode = TileMode.Clamp,
): Brush
Creates a radial gradient with the given colors evenly dispersed within the gradient
Brush.radialGradient( listOf(Color.Red, Color.Green, Color.Blue), center = Offset(side1 / 2.0f, side2 / 2.0f), radius = side1 / 2.0f, tileMode = TileMode.Repeated
)
Parameters
colors | Colors to be rendered as part of the gradient |
center | Center position of the radial gradient circle. If this is set to Offset.Unspecified then the center of the drawing area is used as the center for the radial gradient. Float.POSITIVE_INFINITY can be used for either Offset.x or Offset.y to indicate the far right or far bottom of the drawing area respectively. |
radius | Radius for the radial gradient. Defaults to positive infinity to indicate the largest radius that can fit within the bounds of the drawing area |
tileMode | Determines the behavior for how the shader is to fill a region outside its bounds. Defaults to TileMode.Clamp to repeat the edge pixels |
fun sweepGradient(
vararg colorStops: Pair<Float, Color>,
center: Offset = Offset.Unspecified,
): Brush
Creates a sweep gradient with the given colors dispersed around the center with offsets defined in each colorstop pair. The sweep begins relative to 3 o'clock and continues clockwise until it reaches the starting position again.
Ex:
Brush.sweepGradient( 0.0f to Color.Red, 0.3f to Color.Green, 1.0f to Color.Blue, center = Offset(0.0f, 100.0f)
)
Parameters
colorStops | Colors and offsets to determine how the colors are dispersed throughout the sweep gradient |
center | Center position of the sweep gradient circle. If this is set to Offset.Unspecified then the center of the drawing area is used as the center for the sweep gradient |
fun sweepGradient(colors: List<Color>, center: Offset = Offset.Unspecified): Brush
Creates a sweep gradient with the given colors dispersed evenly around the center. The sweep begins relative to 3 o'clock and continues clockwise until it reaches the starting position again.
Ex:
Brush.sweepGradient( listOf(Color.Red, Color.Green, Color.Blue), center = Offset(10.0f, 20.0f)
)
Parameters
colors | List of colors to fill the sweep gradient |
center | Center position of the sweep gradient circle. If this is set to Offset.Unspecified then the center of the drawing area is used as the center for the sweep gradient |
fun composite(dstBrush: Brush, srcBrush: Brush, blendMode: BlendMode): Brush
Creates a composited result between 2 Brush
instances and the specified BlendMode. The
specified destination and source Brush
inputs will be consumed as the source and
destination images for the corresponding blending algorithm.
Parameters
dstBrush | ShaderBrush used as the destination content |
srcBrush | ShaderBrush used as the source content |
blendMode | BlendMode used to composite the source against the destination shader |