UNPKG

6.15 kBTypeScriptView Raw
1/**
2 * Draw a circle.
3 *
4 * @param ctx - The context this shape will be rendered to.
5 * @param x - The position of the center on the x axis.
6 * @param y - The position of the center on the y axis.
7 * @param r - The radius of the circle.
8 */
9export declare function drawCircle(ctx: CanvasRenderingContext2D, x: number, y: number, r: number): void;
10/**
11 * Draw a square.
12 *
13 * @param ctx - The context this shape will be rendered to.
14 * @param x - The position of the center on the x axis.
15 * @param y - The position of the center on the y axis.
16 * @param r - Half of the width and height of the square.
17 */
18export declare function drawSquare(ctx: CanvasRenderingContext2D, x: number, y: number, r: number): void;
19/**
20 * Draw an equilateral triangle standing on a side.
21 *
22 * @param ctx - The context this shape will be rendered to.
23 * @param x - The position of the center on the x axis.
24 * @param y - The position of the center on the y axis.
25 * @param r - Half of the length of the sides.
26 *
27 * @remarks
28 * http://en.wikipedia.org/wiki/Equilateral_triangle
29 */
30export declare function drawTriangle(ctx: CanvasRenderingContext2D, x: number, y: number, r: number): void;
31/**
32 * Draw an equilateral triangle standing on a vertex.
33 *
34 * @param ctx - The context this shape will be rendered to.
35 * @param x - The position of the center on the x axis.
36 * @param y - The position of the center on the y axis.
37 * @param r - Half of the length of the sides.
38 *
39 * @remarks
40 * http://en.wikipedia.org/wiki/Equilateral_triangle
41 */
42export declare function drawTriangleDown(ctx: CanvasRenderingContext2D, x: number, y: number, r: number): void;
43/**
44 * Draw a star.
45 *
46 * @param ctx - The context this shape will be rendered to.
47 * @param x - The position of the center on the x axis.
48 * @param y - The position of the center on the y axis.
49 * @param r - The outer radius of the star.
50 */
51export declare function drawStar(ctx: CanvasRenderingContext2D, x: number, y: number, r: number): void;
52/**
53 * Draw a diamond.
54 *
55 * @param ctx - The context this shape will be rendered to.
56 * @param x - The position of the center on the x axis.
57 * @param y - The position of the center on the y axis.
58 * @param r - Half of the width and height of the diamond.
59 *
60 * @remarks
61 * http://www.html5canvastutorials.com/labs/html5-canvas-star-spinner/
62 */
63export declare function drawDiamond(ctx: CanvasRenderingContext2D, x: number, y: number, r: number): void;
64/**
65 * Draw a rectangle with rounded corners.
66 *
67 * @param ctx - The context this shape will be rendered to.
68 * @param x - The position of the center on the x axis.
69 * @param y - The position of the center on the y axis.
70 * @param w - The width of the rectangle.
71 * @param h - The height of the rectangle.
72 * @param r - The radius of the corners.
73 *
74 * @remarks
75 * http://stackoverflow.com/questions/1255512/how-to-draw-a-rounded-rectangle-on-html-canvas
76 */
77export declare function drawRoundRect(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number, r: number): void;
78/**
79 * Draw an ellipse.
80 *
81 * @param ctx - The context this shape will be rendered to.
82 * @param x - The position of the center on the x axis.
83 * @param y - The position of the center on the y axis.
84 * @param w - The width of the ellipse.
85 * @param h - The height of the ellipse.
86 *
87 * @remarks
88 * http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
89 *
90 * Postfix '_vis' added to discern it from standard method ellipse().
91 */
92export declare function drawEllipse(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number): void;
93/**
94 * Draw an isometric cylinder.
95 *
96 * @param ctx - The context this shape will be rendered to.
97 * @param x - The position of the center on the x axis.
98 * @param y - The position of the center on the y axis.
99 * @param w - The width of the database.
100 * @param h - The height of the database.
101 *
102 * @remarks
103 * http://stackoverflow.com/questions/2172798/how-to-draw-an-oval-in-html5-canvas
104 */
105export declare function drawDatabase(ctx: CanvasRenderingContext2D, x: number, y: number, w: number, h: number): void;
106/**
107 * Draw a dashed line.
108 *
109 * @param ctx - The context this shape will be rendered to.
110 * @param x - The start position on the x axis.
111 * @param y - The start position on the y axis.
112 * @param x2 - The end position on the x axis.
113 * @param y2 - The end position on the y axis.
114 * @param pattern - List of lengths starting with line and then alternating between space and line.
115 *
116 * @author David Jordan
117 * @remarks
118 * date 2012-08-08
119 * http://stackoverflow.com/questions/4576724/dotted-stroke-in-canvas
120 */
121export declare function drawDashedLine(ctx: CanvasRenderingContext2D, x: number, y: number, x2: number, y2: number, pattern: number[]): void;
122/**
123 * Draw a hexagon.
124 *
125 * @param ctx - The context this shape will be rendered to.
126 * @param x - The position of the center on the x axis.
127 * @param y - The position of the center on the y axis.
128 * @param r - The radius of the hexagon.
129 */
130export declare function drawHexagon(ctx: CanvasRenderingContext2D, x: number, y: number, r: number): void;
131declare const shapeMap: {
132 circle: typeof drawCircle;
133 dashedLine: typeof drawDashedLine;
134 database: typeof drawDatabase;
135 diamond: typeof drawDiamond;
136 ellipse: typeof drawEllipse;
137 ellipse_vis: typeof drawEllipse;
138 hexagon: typeof drawHexagon;
139 roundRect: typeof drawRoundRect;
140 square: typeof drawSquare;
141 star: typeof drawStar;
142 triangle: typeof drawTriangle;
143 triangleDown: typeof drawTriangleDown;
144};
145/**
146 * Returns either custom or native drawing function base on supplied name.
147 *
148 * @param name - The name of the function. Either the name of a
149 * CanvasRenderingContext2D property or an export from shapes.ts without the
150 * draw prefix.
151 *
152 * @returns The function that can be used for rendering. In case of native
153 * CanvasRenderingContext2D function the API is normalized to
154 * `(ctx: CanvasRenderingContext2D, ...originalArgs) => void`.
155 */
156export declare function getShape(name: keyof CanvasRenderingContext2D | keyof typeof shapeMap): any;
157export {};
158//# sourceMappingURL=shapes.d.ts.map
\No newline at end of file