Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

new abstract class lines with methods addPoint, delPoint(), points() …

…was add.
  • Loading branch information...
commit 0e00cc025b94c047e8e7c056eda3ec90c6920a1f 1 parent 3e2c381
@apsavin authored
View
4,349 compile/compiled.js → compile/jCanvaScript.1.1.3.js
2,193 additions, 2,156 deletions not shown
View
0  jCanvaScript.1.1.js → jCanvaScript.1.1.3.js
File renamed without changes
View
BIN  myPackager.exe
Binary file not shown
View
48 objects/lines.js
@@ -0,0 +1,48 @@
+jCanvaScript.line=function(points,color,fill)
+{
+ var line = lines(color,fill);
+ line.pointNames=['x','y'];
+ if(points!==undefined)line.points(points);
+ line.draw=function(ctx)
+ {
+ if(this.x0===undefined)return;
+ ctx.moveTo(this.x0.val,this.y0.val);
+ for(var j=1;j<this.shapesCount;j++)
+ {
+ ctx.lineTo(this['x'+j].val,this['y'+j].val);
+ }
+ }
+ return line;
+}
+jCanvaScript.qCurve=function(points,color,fill)
+{
+ var qCurve = lines(points,color,fill);
+ qCurve.pointNames=['x','y','cp1x','cp1y'];
+ if(points!==undefined)qCurve.points(points);
+ qCurve.draw=function(ctx)
+ {
+ if(this.x0===undefined)return;
+ ctx.moveTo(this.x0.val,this.y0.val);
+ for(var j=1;j<this.shapesCount;j++)
+ {
+ ctx.quadraticCurveTo(this['cp1x'+j].val,this['cp1y'+j].val,this['x'+j].val,this['y'+j].val);
+ }
+ }
+ return qCurve;
+}
+jCanvaScript.bCurve=function(points,color,fill)
+{
+ var bCurve = lines(points,color,fill);
+ bCurve.pointNames=['x','y','cp1x','cp1y','cp2x','cp2y'];
+ if(points!==undefined)bCurve.points(points);
+ bCurve.draw=function(ctx)
+ {
+ if(this.x0===undefined)return;
+ ctx.moveTo(this.x0.val,this.y0.val);
+ for(var j=1;j<this.shapesCount;j++)
+ {
+ ctx.bezierCurveTo(this['cp1x'+j].val,this['cp1y'+j].val,this['cp2x'+j].val,this['cp2y'+j].val,this['x'+j].val,this['y'+j].val);
+ }
+ }
+ return bCurve;
+}
View
69 objects/shapes.js
@@ -34,75 +34,6 @@ jCanvaScript.arc=function(x,y,radius,startAngle,endAngle,anticlockwise,color,fil
};
return arc;
}
-jCanvaScript.line=function(points,color,fill)
-{
- var line = shapes(points[0][0],points[0][1],color,fill);
- for(var j=0;j<points.length;j++)
- {
- line['x'+j]={val:points[j][0]};
- line['y'+j]={val:points[j][1]};
- }
- line.shapesCount=points.length;
- line.addPoint=function(x,y){
- this['x'+this.shapesCount]={val:x};
- this['y'+this.shapesCount]={val:y};
- this.shapesCount++;
- }
- line.draw=function(ctx)
- {
- ctx.moveTo(this.x0.val,this.y0.val);
- for(var j=1;j<this.shapesCount;j++)
- {
- ctx.lineTo(this['x'+j].val,this['y'+j].val);
- }
- }
- return line;
-}
-jCanvaScript.qCurve=function(points,color,fill)
-{
- var qCurve = shapes(points[0][0],points[0][1],color,fill);
- qCurve.fill={val:fill||0};
- for(var j=0;j<points.length;j++)
- {
- qCurve['x'+j]={val:points[j][0]}
- qCurve['y'+j]={val:points[j][1]}
- qCurve['cp1x'+j]={val:points[j][2]}
- qCurve['cp1y'+j]={val:points[j][3]}
- }
- qCurve.shapesCount=points.length;
- qCurve.draw=function(ctx)
- {
- ctx.moveTo(this.x0.val,this.y0.val);
- for(var j=1;j<this.shapesCount;j++)
- {
- ctx.quadraticCurveTo(this['cp1x'+j].val,this['cp1y'+j].val,this['x'+j].val,this['y'+j].val);
- }
- }
- return qCurve;
-}
-jCanvaScript.bCurve=function(points,color,fill)
-{
- var bCurve = shapes(points[0][0],points[0][1],color,fill);
- for(var j=0;j<points.length;j++)
- {
- bCurve['x'+j]={val:points[j][0]};
- bCurve['y'+j]={val:points[j][1]};
- bCurve['cp1x'+j]={val:points[j][2]};
- bCurve['cp1y'+j]={val:points[j][3]};
- bCurve['cp2x'+j]={val:points[j][4]};
- bCurve['cp2y'+j]={val:points[j][5]};
- }
- bCurve.shapesCount=points.length;
- bCurve.draw=function(ctx)
- {
- ctx.moveTo(this.x0.val,this.y0.val);
- for(var j=1;j<this.shapesCount;j++)
- {
- ctx.bezierCurveTo(this['cp1x'+j].val,this['cp1y'+j].val,this['cp2x'+j].val,this['cp2y'+j].val,this['x'+j].val,this['y'+j].val);
- }
- }
- return bCurve;
-}
jCanvaScript.text = function(string,x,y,maxWidth,color,fill)
{
if (maxWidth!==undefined)
View
56 privateObjects/lines.js
@@ -0,0 +1,56 @@
+function lines(color,fill){
+ var lines=shapes(0,0,color,fill);
+ lines.shapesCount=0;
+ lines.addPoint=function(){
+ redraw(this);
+ var names=this.pointNames;
+ for(var i=0;i<names.length;i++)
+ this[names[i]+this.shapesCount]={val:arguments[i]};
+ this.shapesCount++;
+ return this;
+ }
+ lines.delPoint=function(x,y,radius){
+ redraw(this);
+ if(y===undefined)
+ {
+ var points=this.points();
+ points.splice(x,1)
+ this.points(points);
+ }
+ else{
+ radius=radius||0;
+ for(var j=0;j<this.shapesCount;j++)
+ if(this['x'+j].val<x+radius && this['x'+j].val>x-radius && this['y'+j].val<y+radius && this['y'+j].val<y+radius)
+ {
+ this.delPoint(j);
+ j--;
+ }
+ }
+ return this;
+ }
+ lines.points=function(points)
+ {
+ var names=this.pointNames;
+ if(points===undefined){
+ points=[];
+ for(var j=0;j<this.shapesCount;j++)
+ {
+ points[j]=[];
+ for(var i=0;i<names.length;i++)
+ points[j][i]=this[names[i]+j].val;
+ }
+ return points;
+ }
+ redraw(this);
+ var oldCount=this.shapesCount;
+ this.shapesCount=points.length;
+ for(j=0;j<this.shapesCount;j++)
+ for(i=0;i<names.length;i++)
+ this[names[i]+j]={val:points[j][i]};
+ for(j=this.shapesCount;j<oldCount;j++)
+ for(i=0;i<names.length;i++)
+ this[names[i]+j]=undefined;
+ return this;
+ }
+ return lines;
+}
Please sign in to comment.
Something went wrong with that request. Please try again.