Open, Closed and Filled Polygons,
Bezier Lines and
Regions Creation

The functions cdBegin, cdVertex and cdEnd are use for many situations. cdBegin is called once, cdVertex can be called many times, and cdEnd is called once to actually do something. If you call cdBegin again before cdEnd the process is restarted, except for cdBegin(CD_REGION) that can contains one or more polygons inside.

void cdCanvasBegin(cdCanvas* canvas, int mode); [in C]

canvas:Begin(mode: number) [in Lua]

Starts defining a polygon to be drawn (or filled) according to the mode:  CD_CLOSED_LINES, CD_OPEN_LINES, CD_FILL, CD_CLIP, CD_REGION or CD_BEZIER. Do not create embedded polygons, that is, do not call function cdBegin twice without a call to cdEnd in between.

Open, Closed and Filled Polygons

Bezier Lines

void cdCanvasVertex(cdCanvas* canvas, int x, int y); [in C]
void cdfCanvasVertex(cdCanvas* canvas, double x, double y); [in C]
void wdCanvasVertex(cdCanvas* canvas, double x, double y); (WC) [in C]

canvas:Vertex(x, y: number) [in Lua]
canvas:wVertex(x, y: number) (WC) [in Lua]

Adds a vertex to the polygon definition.

void cdCanvasEnd(cdCanvas* canvas); [in C]

canvas:End() [in Lua]

Ends the polygon's definition and draws it.

void cdCanvasPathSet(cdCanvas* canvas, int action); [in C]

canvas:PathSet(action: number) [in Lua]

Configures the action between sequences of cdCanvasVertex. action can be:

So the normal path creation to draw a line will do:

cdCanvasBegin(canvas, CD_PATH);
cdCanvasPathSet(canvas, CD_PATH_MOVETO);
cdCanvasVertex(canvas, x1, y1);
cdCanvasPathSet(canvas, CD_PATH_LINETO);
cdCanvasVertex(canvas, x2, y2);
cdCanvasPathSet(canvas, CD_PATH_CURVETO);
cdCanvasVertex(canvas, x3, y3);  /* control point for start point */ 
cdCanvasVertex(canvas, x4, y4);  /* control point for end point */
cdCanvasVertex(canvas, x5, y5);  /* end point */
cdCanvasPathSet(canvas, CD_PATH_ARC);
cdCanvasVertex(canvas, x6, y6);  /* center */
cdCanvasVertex(canvas, x7, y7);  /* width, height */
cdCanvasVertex(canvas, x8, y8);  /* start angle, end angle (degrees / 1000) */
cdCanvasPathSet(canvas, CD_PATH_STROKE);