Skip to content

Instantly share code, notes, and snippets.

@quickgrid
Created April 9, 2016 19:50
Show Gist options
  • Save quickgrid/0612cfa84dc64ed7616c6139cb0690cc to your computer and use it in GitHub Desktop.
Save quickgrid/0612cfa84dc64ed7616c6139cb0690cc to your computer and use it in GitHub Desktop.
KShapeJS library to extend features of konva JS framework
/*
* Author: Asif Ahmed
* Site: quickgrid.blogspot.com
* Description: kshapejs is a simple javascript library based on konvajs.
* It allow creating some basic shapes not defined in konva
* library.
*/
(function(window){
'use strict';
function define_library(){
var kshapejs = {};
// Takes x,y coordinates of triangle which is left top most point and the triangle size, stroke width
kshapejs.drawTriangle = function(tx, ty, trisize, tstrokewidth){
var triangle = [ tx, ty, tx, ty + trisize, tx + trisize, ty + trisize / 2 ];
var poly = new Konva.Line({
points: triangle,
stroke: 'black',
strokeWidth: tstrokewidth,
closed : true
});
return poly;
}
return kshapejs;
}
//define globally if it doesn't already exist
if(typeof(kshapejs) === 'undefined'){
window.kshapejs = define_library();
}
else{
console.log("kshapejs already defined.");
}
})(window);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment