Drawing points, lines and polygons
- scrupp.draw(table)
- This function can draw points, lines and polygons. The array part of
the table contains the list of x,y coordinate pairs of the
points. The interpretation of those points depends on several settings
made by the following key-value pairs. All of them are optional.
- color [= {255, 255, 255, 255}]
- This table sets the color of the point(s), line(s) or polygon(s)
to the given value. The first three elements are the red, green and
blue components of the color. The optional fourth value is the alpha
component. All four elements have to be in the range from 0 to 255.
The default color is opaque white.
- size [= 1]
- Sets the pixel size or line width to the chosen number. The
default value is 1.
- centerX [= 0] and centerY [= 0]
- These are the coordinates of the center of scaling and rotation.
- scaleX [= 1] and scaleY [= 0]
- Define the scale factor of the x- and y-axis.
- rotate [= 0]
- The angle in degrees to rotate the graphic.
- relative [= false]
- If this boolean value is true, the first point in the array defines
where the graphic should be moved to. All other points in the array are
relative to the first one.
- connect [= false]
- If this boolean value is true and if there are more than two
points a line will be drawn between the first and the second,
the second and the third and so on. The default value is false.
- fill [= false]
- If this boolean value is true the created shape will be filled
with the chosen color. The default value is false.
- antialiasing [= false]
- This boolean value activates or deactivates the anti-aliasing.
If it is true, lines will blend nicely with the background.
The default value is false.
- pixellist [= false]
- If the boolean value pixellist is true, a point
will be drawn at each location given by the coordinate pairs. If it
is false and there is more than one point, the interpretation of the
coordinate pairs depends on the other options:
- fill is true: polygon is drawn
- fill is false and connect is true: connected lines are drawn
- fill is false and connect is false: unconnected lines are drawn;
one between the first and the second point, one between the third and the fourth one and so on
Note:
- Pixel with a size greater than one cannot be rotated; use a filled rectangle instead
- Pixel disappear when the center leaves the viewable area
- The antialiasing of pixel with a size greater than one depends on the graphics card driver
and the OpenGL implementation. Sometimes, they are rendered as circles and sometimes not.
Example
scrupp.init("Draw Test - Click to test!", 600, 400, 32, false)
-- prepare one table for big white pixels
local pixels = { antialiasing = false, size = 20, pixellist = true }
-- prepare one table for red connected lines
local lines = { color = {255,0,0}, antialiasing = true, connect = true }
main = {
render = function(dt)
scrupp.draw(lines)
scrupp.draw(pixels)
end,
mousepressed = function(x, y, button)
-- add the point where the mouse was pressed to the list of pixels
pixels[#pixels+1] = x
pixels[#pixels+1] = y
-- add the point to the list of lines, too
lines[#lines+1] = x
lines[#lines+1] = y
end
}