Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Path
- {
- constructor(context)
- {
- if(!(context instanceof CanvasRenderingContext2D)) throw new Error("Invalid Rendering Context");
- this.context= context;
- let nodes = [];
- let closed = false;
- this.getNodes = function ()
- {
- return nodes;
- }
- this.getPathClose = function ()
- {
- return closed;
- }
- this.define = function (n, c)
- {
- if(!(n instanceof Array)) throw new Error("Nodes are provided in arrays.");
- nodes = n;
- closed = c && true;
- return this;
- }
- this.addNode = function(n)
- {
- if(!(n instanceof Array)) throw new Error("Invalid Node");
- if(!(typeof n[0] == "number" && typeof n[1] == "number" ) ) throw new Error("Invalid Node Coordination");
- this.getNodes().push(n);
- return this;
- }
- return this;
- }
- stroke()
- {
- var a = this.getNodes(),
- i = 0;
- this.context.beginPath();
- this.context.moveTo( a[0][0], a[0][1] );
- while ( ++i < a.length ) this.context.lineTo( a[i][0], a[i][1] );
- if( this.getPathClose() ) this.context.closePath();
- this.context.stroke();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement