- 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.
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 between0.0
to1.0
are visible, but any other positions might impact the gradient). - values are a
number
: a color inRGBA
format.
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("LuaRT.png")
local gradient = canvas:RadialGradient { [0] = 0xffffe600, [1] = 0x000000FF }
gradient.radius = { canvas.width/4, canvas.height/4 }
function canvas:onPaint()
self:begin()
logo:draw(20, 100, 1, 1, "linear")
self:fillrect(0, 0, canvas.width, canvas.height, gradient)
self:flip()
end
function canvas:onHover(x,y, buttons)
gradient.center = { x, y }
end
ui.run(win):wait()