The Brushes module lets you create colors and apply them to different kinds of brushes.
For more info on how brushes are drawn, check out WPF LinearGradientBrush and WPF RadialGradientBrush or have a look at the LUA examples.
Note: To actually draw the brushes, see the Drawing section.
Overview
- GetColor
- GetRandomColor
- GetRelativeColor
- GetSolidColorBrush
- GetLinearGradientBrush
- GetRadialGradientBrush
Functions
GetColor
Creates a color using the given variables.
Syntax:
color GetColor(string hexCode)
color GetColor(int a, int r, int g, int b)
Required arguments
- hexCode: A hex color notation, such as
#0066ff
Alternative arguments
- a: A byte alpha value (0-255)
- r: A byte red value (0-255)
- g: A byte green value (0-255)
- b: A byte blue value (0-255)
Example:
local blueColor = Brushes.GetColor("#0066ff")
local redColor = Brushes.GetColor(255, 255, 0, 0)
GetRandomColor
Returns a pseudo-random color within the RGB spectrum.
Syntax:
color GetRandomColor()
Example:
local randomColor = Brushes.GetRandomColor()
GetRelativeColor
Returns the color at the given position in a gradient, relative to the gradient's start.
Syntax:
color GetRelativeColor(table gradientColors, double position)
Required arguments
- gradientColors: A table using colors as keys and doubles as offsets
- position: A position between 0 and 1.
Example:
-- Create a table and add keys to it (the color) and values (the offset).
local colors = {}
colors[Brushes.GetColor(255, 255, 0, 0)] = 0 -- red
colors[Brushes.GetColor(255, 255, 255, 0)] = 1 -- yellow
-- Get the color that is in the middle of the gradient, between red and yellow
local orange = Brushes.GetRelativeColor(colors, 0.5)
Result:
The function will look at the color in the middle, at 0.5 and it is orange

GetSolidColorBrush
Returns a brush with one color
Syntax:
brush GetSolidColorBrush(color brushColor)
Required arguments
- color: The color the brush will be
Example:
-- Create a red color
local redColor = Brushes.GetColor(255, 255, 0, 0)
-- Create the brush using the newly created color
local redBrush = Brushes.GetSolidColorBrush(redColor)
Result:
Drawing the first brush would look like this:

GetLinearGradientBrush
Returns a brush with a linear gradient
Syntax:
brush GetLinearGradientBrush(table gradientColors, [double startX, double startY, double endX, double endY])
Required arguments
- gradientColors: A table using colors as keys and doubles as offsets
Optional arguments
Note: The arguments between [brackets] are optional and you can leave them out.
- startX: The relative X value of the start position of the gradient
- startY: The relative Y value of the start position of the gradient
- endX: The relative X value of the end position of the gradient
- endY: The relative Y value of the end position of the gradient
Example:
-- Create a table and add keys to it (the color) and values (the offset).
local colors = {}
colors[Brushes.GetColor(255, 255, 0, 0)] = 0 -- red
colors[Brushes.GetColor(255, 255, 0, 255)] = 0.16 -- purple
colors[Brushes.GetColor(255, 0, 0, 255)] = 0.33 -- blue
colors[Brushes.GetColor(255, 0, 255, 255)] = 0.5 -- cyan
colors[Brushes.GetColor(255, 0, 255, 0)] = 0.66 -- green
colors[Brushes.GetColor(255, 255, 255, 0)] = 0.83 -- yellow
colors[Brushes.GetColor(255, 255, 0, 0)] = 1 -- red
-- Create the brush using the newly created color
local rainbowBrush = Brushes.GetLinearGradientBrush(colors)
-- Create another brush using the optional arguments
local horizontalBrush = Brushes.GetLinearGradientBrush(colors, 0, 0.5, 1, 0.5)
Result:
Drawing the first brush would look like this:

Drawing the second brush would look like this:

GetRadialGradientBrush
Returns a brush with a radial gradient
Syntax:
brush GetRadialGradientBrush(table gradientColors, [double centerX, double centerY, double originX, double originY])
Required arguments
- gradientColors: A table using colors as keys and doubles as offsets
Optional arguments
Note: The arguments between [brackets] are optional and you can leave them out.
- centerX: The relative X value of the center position of the gradient
- centerY: The relative Y value of the center position of the gradient
- originX: The relative X value of the origin position of the gradient
- originY: The relative Y value of the origin position of the gradient
Example:
-- Create a table and add keys to it (the color) and values (the offset).
local colors = {}
colors[Brushes.GetColor(255, 255, 0, 0)] = 0 -- red
colors[Brushes.GetColor(255, 255, 0, 255)] = 0.16 -- purple
colors[Brushes.GetColor(255, 0, 0, 255)] = 0.33 -- blue
colors[Brushes.GetColor(255, 0, 255, 255)] = 0.5 -- cyan
colors[Brushes.GetColor(255, 0, 255, 0)] = 0.66 -- green
colors[Brushes.GetColor(255, 255, 255, 0)] = 0.83 -- yellow
colors[Brushes.GetColor(255, 255, 0, 0)] = 1 -- red
-- Create the brush using the newly created color
local circle = Brushes.GetRadialGradientBrush(colors)
-- Create another brush putting the origin in the top left (0,0) resulting in a spotlight
local spotlight = Brushes.GetRadialGradientBrush(colors, 0.5, 0.5, 0, 0)
Result:
Drawing the first brush would look like this:

Drawing the second brush would look like this:
