GradientPaint

Parent Paint
Library display.*
Revision Release 2022.3683
Keywords gradient paint
See also object.fill
object.stroke

Overview

A gradient paint creates a linear progression from one color to another.

Syntax

local paint = {
    type = "gradient",
    color1 = { r,g,b,a },
    color2 = { r,g,b,a },
    direction =
}
type (required)

String. String value of "gradient".

color1 (required)

Array. An RGB+A array of color channels for the start color. Each number should range between 0 and 1 and represent the corresponding value for that channel.

color2 (required)

Array. An RGB+A array of color channels for the end color. Each number should range between 0 and 1 and represent the corresponding value for that channel.

direction (optional)

String. The direction of the gradient from color1 to color2. This can be "down", "up", "left", or "right". Default is "down".

If number. is passed as direction parameter, "down" would be used and fill.rotation would be applied its value.

Properties

(Inherits properties from Paint)

Example

local paint = {
    type = "gradient",
    color1 = { 1, 0, 0.4 },
    color2 = { 1, 0, 0, 0.2 },
    direction = "down"
}

local rect = display.newRect( 200, 200, 300, 300 )
rect.fill = paint