Canvas:line(x0, y0, x1, y1, [ brush ], [ width ] ) method
Draws a line on the Canvas
Parameters
x0
A number representing the horizontal position of the starting point (zero means the left side of the Canvas)
y0
A number representing the horizontal vertical of the starting point (zero means the top side of the Canvas)
x1
A number representing the horizontal position of the ending point
y1
A number representing the horizontal vertical of the ending point
[ brush ]
An optional value that can represent any of the following values :
- A RGBA color, as an integer value
- LinearGradient : The line will be drawn with a colored linear gradient
- RadialGradient : The line will be drawn with a colored radial gradient
- Image : The line will be drawn with a picture pattern.
[ width ]
An optional number value representing the line thickness, defaulting to 1
Return value
This function returns no value.Example
local ui = require "ui"
require "canvas"
-- create a simple Window
local win = ui.Window("Canvas.line() sample", "fixed", 500, 400)
-- create a Canvas
local canvas = ui.Canvas(win)
canvas.align = "all"
canvas.bgcolor = 0x000000FF
local w = canvas.width
local h = canvas.height
function canvas:onPaint()
self:begin()
self:line(math.random(w), math.random(w), math.random(h), math.random(h), math.random(0xFFFFFFFF), 3)
self:flip()
end
ui.run(win):wait()