Paint.line

From codeTank

Jump to: navigation, search

Contents

Description

paint.line will draw a line in a window. It must be used on a paint object, which is passed to the onpaint event when a window needs to be redrawn.

Arguments

-- pnt is a paint object

-- absolute drawing (includes start point and end point)
pnt:line(x1, y1, x2, y2)
pnt:line(x1, y1, x2, y2, color)
pnt:line(x1, y1, x2, y2, color, thickness)

-- relative drawing (draws a line relative to where it was last drawn)
pnt:line(x2, y2)
pnt:line(x2, y2, color)
pnt:line(x2, y2, color, thickness)

paint.line has two ways to be called. The first way is to provide a start point (x1, y1) and end point (x2, y2). The second way is to only provide an end point (x2, y2), and the start point is taken from the previous drawing operation. This is useful for drawing a series of connected lines.

color is optional, and defaults to black if none is provided. Use rgb to generate a color.

thickness is how thick the line is. The default value is 0, which means it's one pixel thick. Larger values produce thicker lines.

Returns

paint.line doesn't return anything.

Example

wnd = window.create{
        width = 300,
        height = 300,
        onpaint = function(wnd, pnt)
                -- draws a black line, 1 pixel thick
                pnt:line(100, 100, 200, 200)
                -- since this only provides one coordinate, it will
                -- draw the line from where the previous line ended
                pnt:line(100, 150)
                -- draw a thick red line
                pnt:line(150, 50, 10, 200, rgb(255, 0, 0), 10)
                -- continues previous line, but now is blue and 5 pixels thick
                pnt:line(50, 50, rgb(0, 0, 255), 5)
                pnt:line(250, 70, rgb(0, 0, 255), 5)
            end,
    }

while window.getcount() > 0 do
    window.pumpmessages()
end

See Also

Personal tools