"use strict"
//var s = Snap("#svg");
// sets a default value
function dval(a,b){
return a==null ? b : a;
}
// get the type object
function type2(a){
var t = typeof a;
if(t === 'object'){
if(a === null){ t = 'null'; }
else if(a.constructor === Array){ t = 'array'; }
else if(a.constructor === RegExp){ t = 'regexp'; }
else{
var t2 = Object.prototype.toString(a);
var regex = /^[object (S+?)]$/;
var matches = t2.match(regex) || [];
t = (matches[1] || t).toLowerCase();
}
if(t === 'object'){
if(a instanceof Shape){ t = 'shape'; }
else{
if(a.type != null && ( // is Snap
a.type === 'line' ||
a.type === 'rect' ||
a.type === 'circle' ||
a.type === 'ellipse' ||
a.type === 'path' ||
a.type === 'group'
)){ t='snapshape'; }
}
}
}
else if(t === 'number'){
if(isNaN(a)){ t = 'nan'; }
}
return t;
}
// base object
class Shape{
constructor(x,y,r, sz, grp, c0, c1, lw){
this.x = 0;
this.y = 0;
this.r = 0; // rotate angle
this.s = sz; // scale
this.ox = 0; // ofs
this.oy = 0;
c0 = dval(c0, "#FFF"); // fill color
c1 = dval(c1, "#000"); // line color
lw = dval(lw, 2);
this.grp = s.group(); // line, circle, rect, path, ...
this.grp.attr( {fill: c0, stroke: c1, strokeWidth: lw} );
if(type2(grp) !== 'array' ){ grp = [grp]; } //doesnt work
for(var g in grp){
var gg = grp[g];
var ty = type2(gg);
if(ty === 'snapshape'){ this.grp.add(gg); }
else if(ty === 'string'){
try{
var b = gg.split(/[ ,]+/);
if(b[0] === 'circle'){
gg = s.circle(b[1],b[2],b[3]);
}
else if(b[0] === 'rect'){
gg = s.rect(b[1],b[2],b[3],b[4]);
}
else if(b[0] === 'line'){
gg = s.line(b[1],b[2],b[3],b[4]);
}
else if(b[0] === 'ellipse'){
gg = s.ellipse(b[1],b[2],b[3],b[4]);
}
else{
gg = s.path(gg);
}
this.grp.add(gg);
}
catch(e){}
}
}
this.move(x,y,r);
}
move(x,y,r, sz){
x = dval(x, this.x);
y = dval(y, this.y);
r = dval(r, this.r);
sz = dval(sz, this.s);
var ox = this.ox;
var oy = this.oy;
var m = new Snap.Matrix();
m.translate(x, y);
m.rotate(r, ox,oy);
m.scale(sz,sz, oy,oy);
this.grp.transform(m);
this.x = x;
this.y = y;
this.r = r;
}
rotate(r){
this.move(this.x, this.y, r);
}
scale(s){
this.move(null,null,null, s);
}
ofs(x,y){
this.ox = x;
this.oy = y;
this.move();
}
animate(x1,y1,r1, tm, callback){
var x0 = this.x;
var y0 = this.y;
var r0 = this.r;
var t = this;
Snap.animate(0,1,
function (v){
var x = (x1 - x0)*v + x0;
var y = (y1 - y0)*v + y0;
var r = (r1 - r0)*v + r0;
t.move(x,y,r);
},
tm, mina.easeinout, callback);
}
}
class Shape_acgtr extends Shape{
constructor(x,y,r, sz, c0, c1, lw){
sz *= 0.75;
super(x+15,y, r, sz, [
"M0,0 Q-3,-20,-16,-16 Q-26,-6,-32,-16 Q-52,-30,-59,-8 L-60,0",
"M0,0 Q-3,20,-16,16 Q-26,6,-32,16 Q-52,30,-59,8 L-60,0",
"rect -15,-5,60,10", "rect 40,-6, 17,12",
"circle 42,-8,2", "circle 48,-8,2", "circle 54,-8,2",
"circle 42, 8,2", "circle 48, 8,2", "circle 54, 8,2",
"circle -20,0,8",
], c0, c1, lw);
this.grp[10].attr({fill: '#000'});
this.ofs(-15,0);
//this.scale(0.75);
}
}
class Shape_egtr extends Shape{
constructor(x,y,r, sz, c0, c1, lw){
sz *= 0.75;
super(x+15,y, r, sz, [
"M0,0 Q0,-16,-16,-16 Q-26,-6,-36,-16 Q-58,-30,-60,0",
"M0,0 L-10,0 Q10,30,-16,16 Q-26,6,-36,16 Q-58,30,-60,0",
"rect -20,-5,65,10", "rect 40,-6, 17,12",
"circle 42,-8,2", "circle 48,-8,2", "circle 54,-8,2",
"circle 42, 8,2", "circle 48, 8,2", "circle 54, 8,2",
"rect -27,-5,3,10", "rect -35,-5,3,10"
], c0, c1, lw);
this.grp[10].attr({fill: '#000'});
this.grp[11].attr({fill: '#000'});
this.ofs(-15,0);
//this.scale(0.75);
}
}
class Shape_uke extends Shape{
constructor(x,y,r, sz, c0, c1, lw){
sz *= 0.50;
super(x+15,y, r, sz, [
"M0,0 Q-3,-20,-16,-16 Q-26,-6,-32,-16 Q-46,-26,-54,-6, L-55,0",
"M0,0 Q-3,20,-16,16 Q-26,6,-32,16 Q-46,26,-54,6, L-55,0",
"rect -20,-5,50,10", "rect 30,-6, 17,12",
"circle 34,-8,2", "circle 42,-8,2",
"circle 34, 8,2", "circle 42, 8,2",
"circle -20,0,8",
], c0, c1, lw);
this.grp[8].attr({fill: '#000'});
this.ofs(-15,0);
}
}
class Shape_bj extends Shape{
constructor(x,y,r, sz, c0, c1, lw){
sz *= 0.75;
super(x+15,y, r, sz, [
"circle -40,0, 20", "circle -40,0, 16",
"rect -20,-4,60,8", "rect 40,-6, 17,12",
"circle 44,-8,2", "circle 52,-8,2",
"circle 44, 8,2", "circle 52, 8,2",
"circle 20,-6,2",
], c0, c1, lw);
this.ofs(-15,0);
}
}
class Shape_mando extends Shape{
constructor(x,y,r, sz, c0, c1, lw){
sz *= 0.50;
super(x+15,y, r, sz, [
"M5,0 s-3,-10,-12,-10 s-12,-17,-30,-15"
+" q-3,0,-16,16 L-55,0",
"M5,0 s-3,10,-12,10 s-12,17,-30,15"
+" q-3,0,-16,-16 L-55,0",
"rect -20,-5,50,10", "rect 30,-6, 20,12",
"circle 30,-8,1.5", "circle 42,-8,1.5",
"circle 36,-8,1.5", "circle 48,-8,1.5",
"circle 30,8,1.5", "circle 42,8,1.5",
"circle 36,8,1.5", "circle 48,8,1.5",
"ellipse -20,0,5,8",
], c0, c1, lw);
this.grp[12].attr({fill: '#000'});
this.ofs(-15,0);
}
}
class Shape_fid extends Shape{
constructor(x,y,r, sz, c0, c1, lw){
var c3 = "#000";
var c4 = "#fff";
sz *= 0.50;
super(x+15,y, r, sz, [
"M0,0 c-3,-20,-14,-12,-16,-14 "
+ "l-2,-2 c4,8,-14,8,-12,0"
+ "l-2,2 c-3,1,-2,-6,-14,-2"
+ "c-3,0,-6,4,-8,8"
+ " L-55,0",
"M0,0 c-3,20,-14,12,-16,14 "
+ "l-2,2 c4,-8,-14,-8,-12,0"
+ "l-2,-2 c-3,-1,-2,6,-14,2"
+ "c-3,0,-6,-4,-8,-8"
+ " L-55,0",
"M-35,-3, l0,6 L -58,0",
"M-15,-3 l45,1 l0,4 l-45,1",
"M30,-4 l18,1 l1,3 l-1,3 l-18,1 z",
"circle 34,-8,2", "circle 40,-8,2",
"circle 36, 8,2", "circle 42, 8,2",
"M-35,8 c0,-7,16,5,16,-5 ",
"M-35,-8 c0, 7,16,-5,16,5 ",
], c0, c1, lw);
this.grp[2].attr({fill: c3});
this.grp[3].attr({fill: c3});
this.ofs(-15,0);
this.bow = new Shape( x,y-2, r*-1+10, sz, [
"rect -2,-59,3,5",
"M1,-54 l-5,0 l0,5 s5,50,0,80 l5,5 z",
"circle -2,-50 1.5",
], c3, null, 0);
this.bow.grp[2].attr({fill: c4});
}
}
class Shape_dr extends Shape{
constructor(x,y,r, sz, c0, c1, lw){
super(x+15,y, r, sz, [
//HH
"line 40,30 50,25",
"line 50,-4 50,30",
"ellipse 50,-4 12,3",
"ellipse 50,-8 12,3",
"line 50,-8, 50,-15",
//SN
"M25,-2 l0,10 a12,2 0 1,0 20,0 l0,-10",
"ellipse 35,0 12,2",
//FT
"M-40,0 l0,20 a15,2 0 1,0 30,0 l0,-20",
"ellipse -25,0 15,2",
//HT
"M5,-10 l0,-6 a10,5 0 1,1 20,0 l0,6",
"ellipse 15,-8 10,5",
//KD
"circle 0,10,25",
//RC
"line -27,-20 -27,35",
"ellipse -27,-20 20,4",
"line -27,-20, -27,-30",
//CC
"line 30,-30 30,35",
"ellipse 30,-30 15,4",
"line 30,-30, 30,-40",
], c0, c1, lw);
}
}