CD - Canvas Draw

Lines

Line are segments that connects 2 or more points. The cdLine function includes the 2 given points and draws the line using the foreground color. Line thickness is controlled by the cdLineWidth function. By using function cdLineStyle you can draw dashed lines with some variations. Lines with a style other than continuous are affected by the back opacity attribute and by the background color.


void cdLine(int x1, int y1, int x2, int y2); [in C]
void wdLine(double x1, double y1, double x2, double y2); (WC) [in C]
cd.Line(x1, y1, x2, y2: number) [in Lua]
cd.wLine(x1, y1, x2, y2: number)
(WC) [in Lua]

Draws a line from (x1,y1) to (x2,y2) using the current foreground color and line width and style. Both points are included in the line.

Polygons and Bezier Lines

Open polygons can be created using cdBegin(CD_OPEN_LINES)/cdVertex(x,y)/.../cdEnd().

Closed polygons use the same number of vertices but the last point is automatically connected to the first point. Closed polygons can be created using cdBegin(CD_CLOSED_LINES)/cdVertex(x,y)/.../cdEnd().

Bezier lines can be created using cdBegin(CD_BEZIER)/cdVertex(x,y)/.../cdEnd(). At least 4 vertices must be defined. The two vertices of the middle are the control vertices. A sequence of bezier lines can be defined using more 3 vertices, two control points and an end point, the last point of the previous bezier will be used as the start point.

See the documentation of cdBegin/cdVertex/cdEnd.

void cdRect(int xmin, int xmax, int ymin, int ymax); [in C]
void wdRect(double xmin, double xmax, double ymin, double ymax); (WC) [in C]
cd.Rect(xmin, xmax, ymin, ymax: number) [in Lua]
cd.wRect(xmin, xmax, ymin, ymax: number)
(WC) [in Lua]

Draws a rectangle with no filling. All points in the limits of interval x_min<=x<=x_max, y_min<=y<=y_max will be painted. It is affected by line attributes and the foreground color. If the active driver does not include this primitive, it will be simulated using the cdLine primitive.

void cdArc(int xc, int yc, int w, int h, double angle1, double angle2); [in C]
void wdArc(double xc, double yc, double w, double h, double angle1, double angle2); (WC) [in C]
cd.Arc(xc, yc, w, h, angle1, angle2: number) [in Lua]
cd.wArc(xc, yc, w, h, angle1, angle2: number)
(WC) [in Lua]

Draws the arc of an ellipse aligned with the axis, using the current foreground color and line width and style. It is drawn counter-clockwise. The coordinate (xc,yc) defines the center of the ellipse. Dimensions w and h define the elliptic axes X and Y, respectively.

Angles angle1 and angle2, in degrees define the arc's beginning and end, but they are not the angle relative to the center, except when w==h and the ellipse is reduced to a circle. The arc starts at the point (xc+(w/2)*cos(angle1),yc+(h/2)*sin(angle1)) and ends at (xc+(w/2)*cos(angle2),yc+(h/2)*sin(angle2)). A complete ellipse can be drawn using 0 and 360 as the angles.

The angles are specified so if the size of the ellipse (w x h) is changed, its shape is preserved. So the angles relative to the center are dependent from the ellipse size. The actual angle can be obtained using rangle = atan2((h/2)*sin(angle),(w/2)*cos(angle)).

The angles are given in degrees. To specify the angle in radians, you can use the definition CD_RAD2DEG to multiply the value in radians before passing the angle to CD.

Arc Parameters


Attributes

int cdLineStyle(int style); [in C]
cd.LineStyle(style: number) -> (old_style: number) [in Lua]

Configures the current line style for: CD_CONTINUOUS, CD_DASHED, CD_DOTTED, CD_DASH_DOT, CD_DASH_DOT_DOT, or CD_CUSTOM. Returns the previous value. Default value: CD_CONTINUOUS. Value CD_QUERY simply returns the current value. When CD_CUSTOM is used the cdLineStyleDahes function must be called before to initialize the custom dashes.

Line Styles

void cdLineStyleDashes(int* dashes, int count); [in C]
cd.LineStyleDashes(dashes: table, count: number) -> (old_style: number) [in Lua]

Defines the custom line style dashes. The first value is the lenght of the first dash, the second value is the leght of the first space, and so on. For example: "10 2 5 2" means dash size 10, space size 2, dash size 5, space size 2, and repeats the pattern.

int cdLineWidth(int width); [in C]
double cdLineWidth(double width); (WC) [in C]
cd.LineWidth(width: number) -> (old_width: number) [in Lua]
cd.wLineWidth(width: number) -> (old_width: number) (WC) [in Lua]

Configures the width of the current line (in pixels). Returns the previous value. Default value: 1. Value CD_QUERY simply returns the current value. Valid width interval: >= 1.

In WC, it configures the current line width in millimeters. 

int cdLineJoin(int style); [in C]
cd.LineJoin(style: number) -> (old_style: number) [in Lua]

Configures the current line style for: CD_MITER, CD_BEVEL or CD_ROUND. Returns the previous value. Default value: CD_MITER. Value CD_QUERY simply returns the current value.

Line Joins

int cdLineCap(int style); [in C]
cd.LineCap(style: number) -> (old_style: number) [in Lua]

Configures the current line style for: CD_CAPFLAT, CD_CAPSQUARE or CD_CAPROUND. Returns the previous value. Default value: CD_CAPFLAT. Value CD_QUERY simply returns the current value.

Line Caps