Canvas:RadialGradient(colors) method


Creates an RadialGradient 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 RadialGradient instance.

Example

local ui = require "ui" require "canvas" -- create a simple Window local win = ui.Window("RadialGradient.constructor() sample", "fixed", 500, 400) -- create a Canvas local canvas = ui.Canvas(win) canvas.align = "all" local logo = canvas:Image("examples/canvas/LuaRT.png") local gradient = canvas:RadialGradient { [0] = 0xffffe600, [1] = 0x000000FF } gradient.radius = { canvas.width/4, canvas.height/4 } function canvas:onPaint() logo:draw(20, 100) self:fillrect(0, 0, canvas.width, canvas.height, gradient) end function canvas:onHover(x, y) gradient.center = { x, y } end ui.run(win):wait()