Canvas:LinearGradient(colors) method


Creates an LinearGradient object instance to be used in any Canvas drawing operation.

Parameters

colors

A table where :

  • keys are a number : a relative gradient position (only positions between 0.0 to 1.0 are visible, but any other positions might impact the gradient).
  • values are a number : a color in RGBA format.

  • The color is represented by a number, an RGBA value (one byte per primary color and one byte for alpha channel).
  • A RGBA color can be represented as an hexadecimal number : 0xRRGGBBAA , RR meaning a 8bit hexadecimal red value, and so on.

Return value

This function returns an LinearGradient instance.

Example

local ui = require "ui" require "canvas" -- create a simple Window local win = ui.Window("LinearGradient.constructor() sample", "fixed", 500, 400) -- create a Canvas local canvas = ui.Canvas(win) canvas.align = "all" canvas.bgcolor = 0x000000FF canvas.fontsize = 37.5 canvas.fontstyle = "italic" canvas.fontweight = 900 local gradient = canvas:LinearGradient { [0] = 0x00FFFFFF, [1] = 0x00008bFF } gradient.start = { 0, 0 } gradient.stop = { canvas.width, canvas.height } local angle = 0 function canvas:onPaint() canvas:clear() canvas:rotate(angle) angle = angle + 2 canvas:print("LuaRT Canvas", 150, 130, gradient) end -- update user interface ui.run(win):wait()