Canvas:rect(x0, y0, x1, y1, [ brush ], [ width ] ) method
Draws a rectangle on the Canvas
Parameters
x0
A number representing the x coordinate of the upper left corner (zero means the left side of the Canvas)
y0
A number representing the y coordinate of the upper left corner (zero means the top side of the Canvas)
x1
A number representing the x coordinate of the lower right corner
y1
A number representing the y coordinate of the lower right corner
[ 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 rectangle border 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.rect() 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
local img = canvas:Image("examples/canvas/LuaRT.png")
function canvas:onPaint()
img:draw(math.random(w)-80, math.random(h), math.random(), math.random())
end
win:show()
-- update user interface
repeat
ui.update()
until not win.visible