Game Development Reference
In-Depth Information
Note
While you can set the fill color by using
fill(255,164,0)
or set the pen color by using
stroke(0,0,0)
or the stroke Width by using the
strokeWidth(3)
, you can retrieve these values
by passing nothing to these functions, simply as
fill()
which would return the current fill color,
stroke()
would return the stroke color and
strokeWidth()
would return the width.
Drawing Lines
The function to draw lines is the
line
function. This takes four arguments: the x- and y-coordinates
of the start point and endpoint of the line. The line is drawn between these two points.
line(10,10,300,300) -- draws a line between 10,10 and 300,300
The
line cap
mode is used to determine how the ends of the lines are drawn. There are three
line cap
modes that are used when drawing lines:
ROUND
,
SQUARE
, and
PROJECT
. The default mode is
ROUND
.
ROUND
: Draws the lines with the ends rounded off
SQUARE
: Draws the lines with the ends squared off
PROJECT
: Draws the lines with square edges, but projected out, as in
ROUND
mode.
Anti-Aliasing
When drawing lines, you can end up with jagged edges, which make for an unpleasant visual
experience. To deal with this, Codea has a function that smoothes the edges out—what is known as
anti-aliasing
. To perform anti-aliasing, you call the
smooth
function, all subsequently drawn lines will
be anti-aliased.
Note
While drawing thin lines, you might want to switch to no anti-aliasing using the
noSmooth
function. Thin lines when anti-aliased would look worse than without anti-aliasing.
Drawing Circles and Ellipses
The function to draw a circle or ellipses is the
ellipse
function. This takes four parameters, which
depend on the
ellipse mode
being used to draw the ellipse (discussed following). In one such mode,
CENTER
, the four parameters are the x,y-coordinates of the center point around which the circle is
drawn, followed by the diameters—one for the x-axis and one for the y-axis. If these are the same, a
circle is drawn. If these are different, an ellipse is drawn.