--- /dev/null
+function divide_curve(kage, x1, y1, sx1, sy1, x2, y2, curve, div_curve, off_curve){\r
+ var rate = 0.5;\r
+ var cut = Math.floor(curve.length * rate);\r
+ var cut_rate = cut / curve.length;\r
+ var tx1 = x1 + (sx1 - x1) * cut_rate;\r
+ var ty1 = y1 + (sy1 - y1) * cut_rate;\r
+ var tx2 = sx1 + (x2 - sx1) * cut_rate;\r
+ var ty2 = sy1 + (y2 - sy1) * cut_rate;\r
+ var tx3 = tx1 + (tx2 - tx1) * cut_rate;\r
+ var ty3 = ty1 + (ty2 - ty1) * cut_rate;\r
+ \r
+ div_curve[0] = new Array();\r
+ div_curve[1] = new Array();\r
+ off_curve[0] = new Array(6);\r
+ off_curve[1] = new Array(6);\r
+ \r
+ // must think about 0 : <0\r
+ var i;\r
+ for(i = 0; i <= cut; i++){\r
+ div_curve[0].push(curve[i]);\r
+ }\r
+ off_curve[0][0] = x1;\r
+ off_curve[0][1] = y1;\r
+ off_curve[0][2] = tx1;\r
+ off_curve[0][3] = ty1;\r
+ off_curve[0][4] = tx3;\r
+ off_curve[0][5] = ty3;\r
+ \r
+ for(i = cut; i < curve.length; i++){\r
+ div_curve[1].push(curve[i]);\r
+ }\r
+ off_curve[1][0] = tx3;\r
+ off_curve[1][1] = ty3;\r
+ off_curve[1][2] = tx2;\r
+ off_curve[1][3] = ty2;\r
+ off_curve[1][4] = x2;\r
+ off_curve[1][5] = y2;\r
+}\r
+\r
+// ------------------------------------------------------------------\r
+function find_offcurve(kage, curve, sx, sy, result){\r
+ var nx1, ny1, nx2, ny2, tx, ty;\r
+ var minx, miny, count, diff;\r
+ var tt, t, x, y, ix, iy;\r
+ var mindiff = 100000;\r
+ var area = 8;\r
+ var mesh = 2;\r
+ // area = 10 mesh = 5 -> 281 calcs\r
+ // area = 10 mesh = 4 -> 180 calcs\r
+ // area = 8 mesh = 4 -> 169 calcs\r
+ // area = 7.5 mesh = 3 -> 100 calcs\r
+ // area = 8 mesh = 2 -> 97 calcs\r
+ // area = 7 mesh = 2 -> 80 calcs\r
+ \r
+ nx1 = curve[0][0];\r
+ ny1 = curve[0][1];\r
+ nx2 = curve[curve.length - 1][0];\r
+ ny2 = curve[curve.length - 1][1];\r
+ \r
+ for(tx = sx - area; tx < sx + area; tx += mesh){\r
+ for(ty = sy - area; ty < sy + area; ty += mesh){\r
+ count = 0;\r
+ diff = 0;\r
+ for(tt = 0; tt < curve.length; tt++){\r
+ t = tt / curve.length;\r
+ \r
+ //calculate a dot\r
+ x = ((1.0 - t) * (1.0 - t) * nx1 + 2.0 * t * (1.0 - t) * tx + t * t * nx2);\r
+ y = ((1.0 - t) * (1.0 - t) * ny1 + 2.0 * t * (1.0 - t) * ty + t * t * ny2);\r
+ \r
+ //KATAMUKI of vector by BIBUN\r
+ ix = (nx1 - 2.0 * tx + nx2) * 2.0 * t + (-2.0 * nx1 + 2.0 * tx);\r
+ iy = (ny1 - 2.0 * ty + ny2) * 2.0 * t + (-2.0 * ny1 + 2.0 * ty);\r
+ \r
+ diff += (curve[count][0] - x) * (curve[count][0] - x) + (curve[count][1] - y) * (curve[count][1] - y);\r
+ if(diff > mindiff){\r
+ tt = curve.length;\r
+ }\r
+ count++;\r
+ }\r
+ if(diff < mindiff){\r
+ minx = tx;\r
+ miny = ty;\r
+ mindiff = diff;\r
+ }\r
+ }\r
+ }\r
+ \r
+ for(tx = minx - mesh + 1; tx <= minx + mesh - 1; tx += 0.5){\r
+ for(ty = miny - mesh + 1; ty <= miny + mesh - 1; ty += 0.5){\r
+ count = 0;\r
+ diff = 0;\r
+ for(tt = 0; tt < curve.length; tt++){\r
+ t = tt / curve.length;\r
+ \r
+ //calculate a dot\r
+ x = ((1.0 - t) * (1.0 - t) * nx1 + 2.0 * t * (1.0 - t) * tx + t * t * nx2);\r
+ y = ((1.0 - t) * (1.0 - t) * ny1 + 2.0 * t * (1.0 - t) * ty + t * t * ny2);\r
+ \r
+ //KATAMUKI of vector by BIBUN\r
+ ix = (nx1 - 2.0 * tx + nx2) * 2.0 * t + (-2.0 * nx1 + 2.0 * tx);\r
+ iy = (ny1 - 2.0 * ty + ny2) * 2.0 * t + (-2.0 * ny1 + 2.0 * ty);\r
+ \r
+ diff += (curve[count][0] - x) * (curve[count][0] - x) + (curve[count][1] - y) * (curve[count][1] - y);\r
+ if(diff > mindiff){\r
+ tt = curve.length;\r
+ }\r
+ count++;\r
+ }\r
+ if(diff < mindiff){\r
+ minx = tx;\r
+ miny = ty;\r
+ mindiff = diff;\r
+ }\r
+ }\r
+ }\r
+ \r
+ result[0] = nx1;\r
+ result[1] = ny1;\r
+ result[2] = minx;\r
+ result[3] = miny;\r
+ result[4] = nx2;\r
+ result[5] = ny2;\r
+ result[6] = mindiff;\r
+}\r
+\r
+// ------------------------------------------------------------------\r
+function get_candidate(kage, curve, a1, a2, x1, y1, sx1, sy1, x2, y2){\r
+ var x, y, ix, iy, ir, ia, ib, tt, t, deltad;\r
+ var hosomi = 0.5;\r
+ \r
+ curve[0] = new Array();\r
+ curve[1] = new Array();\r
+ \r
+ for(tt = 0; tt <= 1000; tt = tt + kage.kRate){\r
+ t = tt / 1000;\r
+ \r
+ //calculate a dot\r
+ x = ((1.0 - t) * (1.0 - t) * x1 + 2.0 * t * (1.0 - t) * sx1 + t * t * x2);\r
+ y = ((1.0 - t) * (1.0 - t) * y1 + 2.0 * t * (1.0 - t) * sy1 + t * t * y2);\r
+ \r
+ //KATAMUKI of vector by BIBUN\r
+ ix = (x1 - 2.0 * sx1 + x2) * 2.0 * t + (-2.0 * x1 + 2.0 * sx1);\r
+ iy = (y1 - 2.0 * sy1 + y2) * 2.0 * t + (-2.0 * y1 + 2.0 * sy1);\r
+ //line SUICHOKU by vector\r
+ if(ix != 0 && iy != 0){\r
+ ir = Math.atan(iy / ix * -1);\r
+ ia = Math.sin(ir) * (kage.kMinWidthT);\r
+ ib = Math.cos(ir) * (kage.kMinWidthT);\r
+ }\r
+ else if(ix == 0){\r
+ ia = kage.kMinWidthT;\r
+ ib = 0;\r
+ }\r
+ else{\r
+ ia = 0;\r
+ ib = kage.kMinWidthT;\r
+ }\r
+ \r
+ if(a1 == 7 && a2 == 0){ // L2RD: fatten\r
+ deltad = Math.pow(t, hosomi) * kage.kL2RDfatten;\r
+ }\r
+ else if(a1 == 7){\r
+ deltad = Math.pow(t, hosomi);\r
+ }\r
+ else if(a2 == 7){\r
+ deltad = Math.pow(1.0 - t, hosomi);\r
+ }\r
+ else{ deltad = 1; }\r
+ \r
+ if(deltad < 0.15){\r
+ deltad = 0.15;\r
+ }\r
+ ia = ia * deltad;\r
+ ib = ib * deltad;\r
+ \r
+ //reverse if vector is going 2nd/3rd quadrants\r
+ if(ix <= 0){\r
+ ia = ia * -1;\r
+ ib = ib * -1;\r
+ }\r
+ \r
+ temp = new Array(2);\r
+ temp[0] = x - ia;\r
+ temp[1] = y - ib;\r
+ curve[0].push(temp);\r
+ temp = new Array(2);\r
+ temp[0] = x + ia;\r
+ temp[1] = y + ib;\r
+ curve[1].push(temp);\r
+ }\r
+}\r
this.kKakato = 3;\r
this.kL2RDfatten = 1.1;\r
this.kMage = 10;\r
+ this.kUseCurve = 0;\r
\r
this.kAdjustKakatoL = ([14, 9, 5, 2]); // for KAKATO adjustment 000,100,200,300\r
this.kAdjustKakatoR = ([8, 6, 4, 2]); // for KAKATO adjustment 000,100,200,300\r
hosomi += 0.4 * (1 - Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / 50);\r
}\r
\r
+ //---------------------------------------------------------------\r
+ \r
poly = new Polygon();\r
poly2 = new Polygon();\r
\r
- for(tt = 0; tt <= 1000; tt = tt + kage.kRate){\r
- t = tt / 1000;\r
- \r
- if(sx1 == sx2 && sy1 == sy2){ // Spline\r
- //calculate a dot\r
- x = ((1.0 - t) * (1.0 - t) * x1 + 2.0 * t * (1.0 - t) * sx1 + t * t * x2);\r
- y = ((1.0 - t) * (1.0 - t) * y1 + 2.0 * t * (1.0 - t) * sy1 + t * t * y2);\r
+ if(sx1 == sx2 && sy1 == sy2){ // Spline\r
+ if(kage.kUseCurve){\r
+ // generating fatten curve -- begin\r
+ var kage2 = new Kage();\r
+ kage2.kRate = 10;\r
\r
- //KATAMUKI of vector by BIBUN\r
- ix = (x1 - 2.0 * sx1 + x2) * 2.0 * t + (-2.0 * x1 + 2.0 * sx1);\r
- iy = (y1 - 2.0 * sy1 + y2) * 2.0 * t + (-2.0 * y1 + 2.0 * sy1);\r
- } else { // Bezier\r
- //calculate a dot\r
+ var curve = new Array(2); // L and R\r
+ get_candidate(kage2, curve, a1, a2, x1, y1, sx1, sy1, x2, y2);\r
+ \r
+ var dcl12_34 = new Array(2);\r
+ var dcr12_34 = new Array(2);\r
+ var dpl12_34 = new Array(2);\r
+ var dpr12_34 = new Array(2);\r
+ divide_curve(kage2, x1, y1, sx1, sy1, x2, y2, curve[0], dcl12_34, dpl12_34);\r
+ divide_curve(kage2, x1, y1, sx1, sy1, x2, y2, curve[1], dcr12_34, dpr12_34);\r
+ \r
+ var ncl1 = new Array(7);\r
+ var ncl2 = new Array(7);\r
+ find_offcurve(kage2, dcl12_34[0], dpl12_34[0][2], dpl12_34[0][3], ncl1);\r
+ find_offcurve(kage2, dcl12_34[1], dpl12_34[1][2], dpl12_34[1][3], ncl2);\r
+ \r
+ poly.push(ncl1[0], ncl1[1]);\r
+ poly.push(ncl1[2], ncl1[3], 1);\r
+ poly.push(ncl1[4], ncl1[5]);\r
+ poly.push(ncl2[2], ncl2[3], 1);\r
+ poly.push(ncl2[4], ncl2[5]);\r
+ \r
+ poly2.push(dcr12_34[0][0][0], dcr12_34[0][0][1]);\r
+ poly2.push(dpr12_34[0][2] - (ncl1[2] - dpl12_34[0][2]), dpl12_34[0][3] - (ncl1[3] - dpl12_34[0][3]), 1);\r
+ poly2.push(dcr12_34[0][dcr12_34[0].length - 1][0], dcr12_34[0][dcr12_34[0].length - 1][1]);\r
+ poly2.push(dpr12_34[1][2] - (ncl2[2] - dpl12_34[1][2]), dpl12_34[1][3] - (ncl2[3] - dpl12_34[1][3]), 1);\r
+ poly2.push(dcr12_34[1][dcr12_34[1].length - 1][0], dcr12_34[1][dcr12_34[1].length - 1][1]);\r
+ \r
+ poly2.reverse();\r
+ poly.concat(poly2);\r
+ polygons.push(poly);\r
+ // generating fatten curve -- end\r
+ } else {\r
+ for(tt = 0; tt <= 1000; tt = tt + kage.kRate){\r
+ t = tt / 1000;\r
+ \r
+ // calculate a dot\r
+ x = ((1.0 - t) * (1.0 - t) * x1 + 2.0 * t * (1.0 - t) * sx1 + t * t * x2);\r
+ y = ((1.0 - t) * (1.0 - t) * y1 + 2.0 * t * (1.0 - t) * sy1 + t * t * y2);\r
+ \r
+ // KATAMUKI of vector by BIBUN\r
+ ix = (x1 - 2.0 * sx1 + x2) * 2.0 * t + (-2.0 * x1 + 2.0 * sx1);\r
+ iy = (y1 - 2.0 * sy1 + y2) * 2.0 * t + (-2.0 * y1 + 2.0 * sy1);\r
+ \r
+ // line SUICHOKU by vector\r
+ if(ix != 0 && iy != 0){\r
+ ir = Math.atan(iy / ix * -1);\r
+ ia = Math.sin(ir) * (kage.kMinWidthT);\r
+ ib = Math.cos(ir) * (kage.kMinWidthT);\r
+ }\r
+ else if(ix == 0){\r
+ ia = kage.kMinWidthT;\r
+ ib = 0;\r
+ }\r
+ else{\r
+ ia = 0;\r
+ ib = kage.kMinWidthT;\r
+ }\r
+ \r
+ if(a1 == 7 && a2 == 0){ // L2RD: fatten\r
+ deltad = Math.pow(t, hosomi) * kage.kL2RDfatten;\r
+ }\r
+ else if(a1 == 7){\r
+ deltad = Math.pow(t, hosomi);\r
+ }\r
+ else if(a2 == 7){\r
+ deltad = Math.pow(1.0 - t, hosomi);\r
+ }\r
+ else{ deltad = 1; }\r
+ \r
+ if(deltad < 0.15){\r
+ deltad = 0.15;\r
+ }\r
+ ia = ia * deltad;\r
+ ib = ib * deltad;\r
+ \r
+ //reverse if vector is going 2nd/3rd quadrants\r
+ if(ix <= 0){\r
+ ia = ia * -1;\r
+ ib = ib * -1;\r
+ }\r
+ \r
+ //copy to polygon structure\r
+ poly.push(x - ia, y - ib);\r
+ poly2.push(x + ia, y + ib);\r
+ }\r
+ \r
+ // suiheisen ni setsuzoku\r
+ if(a1 == 132){\r
+ var index = 0;\r
+ while(true){\r
+ if(poly2.array[index].y <= y1 && y1 <= poly2.array[index + 1].y){\r
+ break;\r
+ }\r
+ index++;\r
+ }\r
+ newx1 = poly2.array[index + 1].x + (poly2.array[index].x - poly2.array[index + 1].x) *\r
+ (poly2.array[index + 1].y - y1) / (poly2.array[index + 1].y - poly2.array[index].y);\r
+ newy1 = y1;\r
+ newx2 = poly.array[0].x + (poly.array[0].x - poly.array[1].x) * (poly.array[0].y - y1) /\r
+ (poly.array[1].y - poly.array[0].y);\r
+ newy2 = y1;\r
+ \r
+ for(var i = 0; i < index; i++){\r
+ poly2.shift();\r
+ }\r
+ poly2.set(0, newx1, newy1);\r
+ poly.unshift(newx2, newy2);\r
+ }\r
+ \r
+ poly2.reverse();\r
+ poly.concat(poly2);\r
+ polygons.push(poly);\r
+ }\r
+ } else { // Bezier\r
+ for(tt = 0; tt <= 1000; tt = tt + kage.kRate){\r
+ t = tt / 1000;\r
+ \r
+ // calculate a dot\r
x = (1.0 - t) * (1.0 - t) * (1.0 - t) * x1 + 3.0 * t * (1.0 - t) * (1.0 - t) * sx1 + 3 * t * t * (1.0 - t) * sx2 + t * t * t * x2;\r
y = (1.0 - t) * (1.0 - t) * (1.0 - t) * y1 + 3.0 * t * (1.0 - t) * (1.0 - t) * sy1 + 3 * t * t * (1.0 - t) * sy2 + t * t * t * y2;\r
- //KATAMUKI of vector by BIBUN\r
+ // KATAMUKI of vector by BIBUN\r
ix = t * t * (-3 * x1 + 9 * sx1 + -9 * sx2 + 3 * x2) + t * (6 * x1 + -12 * sx1 + 6 * sx2) + -3 * x1 + 3 * sx1;\r
iy = t * t * (-3 * y1 + 9 * sy1 + -9 * sy2 + 3 * y2) + t * (6 * y1 + -12 * sy1 + 6 * sy2) + -3 * y1 + 3 * sy1;\r
- }\r
- //line SUICHOKU by vector\r
- if(ix != 0 && iy != 0){\r
- ir = Math.atan(iy / ix * -1);\r
- ia = Math.sin(ir) * (kage.kMinWidthT);\r
- ib = Math.cos(ir) * (kage.kMinWidthT);\r
- }\r
- else if(ix == 0){\r
- ia = kage.kMinWidthT;\r
- ib = 0;\r
- }\r
- else{\r
- ia = 0;\r
- ib = kage.kMinWidthT;\r
- }\r
- \r
- if(a1 == 7 && a2 == 0){ // L2RD: fatten\r
- deltad = Math.pow(t, hosomi) * kage.kL2RDfatten;\r
- }\r
- else if(a1 == 7){\r
- deltad = Math.pow(t, hosomi);\r
- }\r
- else if(a2 == 7){\r
- deltad = Math.pow(1.0 - t, hosomi);\r
- }\r
- else{ deltad = 1; }\r
- \r
- if(deltad < 0.15){\r
- deltad = 0.15;\r
- }\r
- ia = ia * deltad;\r
- ib = ib * deltad;\r
- \r
- //reverse if vector is going 2nd/3rd quadrants\r
- if(ix <= 0){\r
- ia = ia * -1;\r
- ib = ib * -1;\r
+ \r
+ // line SUICHOKU by vector\r
+ if(ix != 0 && iy != 0){\r
+ ir = Math.atan(iy / ix * -1);\r
+ ia = Math.sin(ir) * (kage.kMinWidthT);\r
+ ib = Math.cos(ir) * (kage.kMinWidthT);\r
+ }\r
+ else if(ix == 0){\r
+ ia = kage.kMinWidthT;\r
+ ib = 0;\r
+ }\r
+ else{\r
+ ia = 0;\r
+ ib = kage.kMinWidthT;\r
+ }\r
+ \r
+ if(a1 == 7 && a2 == 0){ // L2RD: fatten\r
+ deltad = Math.pow(t, hosomi) * kage.kL2RDfatten;\r
+ }\r
+ else if(a1 == 7){\r
+ deltad = Math.pow(t, hosomi);\r
+ }\r
+ else if(a2 == 7){\r
+ deltad = Math.pow(1.0 - t, hosomi);\r
+ }\r
+ else{ deltad = 1; }\r
+ \r
+ if(deltad < 0.15){\r
+ deltad = 0.15;\r
+ }\r
+ ia = ia * deltad;\r
+ ib = ib * deltad;\r
+ \r
+ //reverse if vector is going 2nd/3rd quadrants\r
+ if(ix <= 0){\r
+ ia = ia * -1;\r
+ ib = ib * -1;\r
+ }\r
+ \r
+ //copy to polygon structure\r
+ poly.push(x - ia, y - ib);\r
+ poly2.push(x + ia, y + ib);\r
}\r
\r
- //copy to polygon structure\r
- poly.push(x - ia, y - ib);\r
- poly2.push(x + ia, y + ib);\r
- }\r
- \r
- // suiheisen ni setsuzoku\r
- if(a1 == 132){\r
- var index = 0;\r
- while(true){\r
- if(poly2.array[index].y <= y1 && y1 <= poly2.array[index + 1].y){\r
- break;\r
+ // suiheisen ni setsuzoku\r
+ if(a1 == 132){\r
+ var index = 0;\r
+ while(true){\r
+ if(poly2.array[index].y <= y1 && y1 <= poly2.array[index + 1].y){\r
+ break;\r
+ }\r
+ index++;\r
+ }\r
+ newx1 = poly2.array[index + 1].x + (poly2.array[index].x - poly2.array[index + 1].x) *\r
+ (poly2.array[index + 1].y - y1) / (poly2.array[index + 1].y - poly2.array[index].y);\r
+ newy1 = y1;\r
+ newx2 = poly.array[0].x + (poly.array[0].x - poly.array[1].x) * (poly.array[0].y - y1) /\r
+ (poly.array[1].y - poly.array[0].y);\r
+ newy2 = y1;\r
+ \r
+ for(var i = 0; i < index; i++){\r
+ poly2.shift();\r
}\r
- index++;\r
+ poly2.set(0, newx1, newy1);\r
+ poly.unshift(newx2, newy2);\r
}\r
- newx1 = poly2.array[index + 1].x + (poly2.array[index].x - poly2.array[index + 1].x) *\r
- (poly2.array[index + 1].y - y1) / (poly2.array[index + 1].y - poly2.array[index].y);\r
- newy1 = y1;\r
- newx2 = poly.array[0].x + (poly.array[0].x - poly.array[1].x) * (poly.array[0].y - y1) /\r
- (poly.array[1].y - poly.array[0].y);\r
- newy2 = y1;\r
\r
- for(var i = 0; i < index; i++){\r
- poly2.shift();\r
- }\r
- poly2.set(0, newx1, newy1);\r
- poly.unshift(newx2, newy2);\r
+ poly2.reverse();\r
+ poly.concat(poly2);\r
+ polygons.push(poly);\r
}\r
\r
- poly2.reverse();\r
- poly.concat(poly2);\r
- polygons.push(poly);\r
- \r
//process for head of stroke\r
rad = Math.atan((sy1 - y1) / (sx1 - x1));\r
if(x1 < sx1){ v = 1; } else{ v = -1; }\r
if(a2 == 1 || a2 == 8 || a2 == 15){ //the last filled circle ... it can change 15->5\r
if(sx2 == x2){\r
poly = new Polygon();\r
- poly.push(x2 - kage.kMinWidthT, y2);\r
- poly.push(x2 - kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7);\r
- poly.push(x2, y2 + kage.kMinWidthT);\r
- poly.push(x2 + kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7);\r
- poly.push(x2 + kage.kMinWidthT, y2);\r
+ if(kage.kUseCurve){\r
+ // by curve path\r
+ poly.push(x2 - kage.kMinWidthT, y2);\r
+ poly.push(x2 - kage.kMinWidthT, y2 + kage.kMinWidthT, 1);\r
+ poly.push(x2, y2 + kage.kMinWidthT);\r
+ poly.push(x2 + kage.kMinWidthT, y2 + kage.kMinWidthT, 1);\r
+ poly.push(x2 + kage.kMinWidthT, y2);\r
+ } else {\r
+ // by polygon\r
+ poly.push(x2 - kage.kMinWidthT, y2);\r
+ poly.push(x2 - kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7);\r
+ poly.push(x2, y2 + kage.kMinWidthT);\r
+ poly.push(x2 + kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7);\r
+ poly.push(x2 + kage.kMinWidthT, y2);\r
+ }\r
polygons.push(poly);\r
}\r
else if(sy2 == y2){\r
poly = new Polygon();\r
- poly.push(x2, y2 - kage.kMinWidthT);\r
- poly.push(x2 + kage.kMinWidthT * 0.7, y2 - kage.kMinWidthT * 0.7);\r
- poly.push(x2 + kage.kMinWidthT, y2);\r
- poly.push(x2 + kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7);\r
- poly.push(x2, y2 + kage.kMinWidthT);\r
+ if(kage.kUseCurve){\r
+ // by curve path\r
+ poly.push(x2 - kage.kMinWidthT, y2);\r
+ poly.push(x2 - kage.kMinWidthT, y2 + kage.kMinWidthT, 1);\r
+ poly.push(x2, y2 + kage.kMinWidthT);\r
+ poly.push(x2 + kage.kMinWidthT, y2 + kage.kMinWidthT, 1);\r
+ poly.push(x2 + kage.kMinWidthT, y2);\r
+ } else {\r
+ // by polygon\r
+ poly.push(x2, y2 - kage.kMinWidthT);\r
+ poly.push(x2 + kage.kMinWidthT * 0.7, y2 - kage.kMinWidthT * 0.7);\r
+ poly.push(x2 + kage.kMinWidthT, y2);\r
+ poly.push(x2 + kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7);\r
+ poly.push(x2, y2 + kage.kMinWidthT);\r
+ }\r
polygons.push(poly);\r
}\r
else{\r
poly = new Polygon();\r
- poly.push(x2 + Math.sin(rad) * kage.kMinWidthT * v, y2 - Math.cos(rad) * kage.kMinWidthT * v);\r
- poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.7 * v + Math.sin(rad) * kage.kMinWidthT * 0.7 * v,\r
- y2 + Math.sin(rad) * kage.kMinWidthT * 0.7 * v - Math.cos(rad) * kage.kMinWidthT * 0.7 * v);\r
- poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * v, y2 + Math.sin(rad) * kage.kMinWidthT * v);\r
- poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.7 * v - Math.sin(rad) * kage.kMinWidthT * 0.7 * v,\r
- y2 + Math.sin(rad) * kage.kMinWidthT * 0.7 * v + Math.cos(rad) * kage.kMinWidthT * 0.7 * v);\r
- poly.push(x2 - Math.sin(rad) * kage.kMinWidthT * v, y2 + Math.cos(rad) * kage.kMinWidthT * v);\r
+ if(kage.kUseCurve){\r
+ poly.push(x2 + Math.sin(rad) * kage.kMinWidthT * v, y2 - Math.cos(rad) * kage.kMinWidthT * v);\r
+ poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.9 * v + Math.sin(rad) * kage.kMinWidthT * 0.9 * v,\r
+ y2 + Math.sin(rad) * kage.kMinWidthT * 0.9 * v - Math.cos(rad) * kage.kMinWidthT * 0.9 * v, 1);\r
+ poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * v, y2 + Math.sin(rad) * kage.kMinWidthT * v);\r
+ poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.9 * v - Math.sin(rad) * kage.kMinWidthT * 0.9 * v,\r
+ y2 + Math.sin(rad) * kage.kMinWidthT * 0.9 * v + Math.cos(rad) * kage.kMinWidthT * 0.9 * v, 1);\r
+ poly.push(x2 - Math.sin(rad) * kage.kMinWidthT * v, y2 + Math.cos(rad) * kage.kMinWidthT * v);\r
+ } else {\r
+ poly.push(x2 + Math.sin(rad) * kage.kMinWidthT * v, y2 - Math.cos(rad) * kage.kMinWidthT * v);\r
+ poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.7 * v + Math.sin(rad) * kage.kMinWidthT * 0.7 * v,\r
+ y2 + Math.sin(rad) * kage.kMinWidthT * 0.7 * v - Math.cos(rad) * kage.kMinWidthT * 0.7 * v);\r
+ poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * v, y2 + Math.sin(rad) * kage.kMinWidthT * v);\r
+ poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.7 * v - Math.sin(rad) * kage.kMinWidthT * 0.7 * v,\r
+ y2 + Math.sin(rad) * kage.kMinWidthT * 0.7 * v + Math.cos(rad) * kage.kMinWidthT * 0.7 * v);\r
+ poly.push(x2 - Math.sin(rad) * kage.kMinWidthT * v, y2 + Math.cos(rad) * kage.kMinWidthT * v);\r
+ }\r
polygons.push(poly);\r
}\r
}\r
tx2 = x2 + kage.kMage * Math.cos(rad) * v;\r
ty2 = y2 + kage.kMage * Math.sin(rad) * v;\r
}\r
- tx3 = x3;\r
+ tx3 = x3;\r
ty3 = y3;\r
\r
cdDrawLine(kage, polygons, x1, y1, tx1, ty1, a2, 1);\r
cdDrawCurve(kage, polygons, tx1, ty1, x2, y2, tx2, ty2, 1, 1);\r
- if(tx3 - tx2 > 0){ // for closer position\r
- cdDrawLine(kage, polygons, tx2, ty2, tx3, ty3, 6, 5); // bolder by force\r
- }\r
+ if(tx3 - tx2 > 0){ // for closer position\r
+ cdDrawLine(kage, polygons, tx2, ty2, tx3, ty3, 6, 5); // bolder by force\r
+ }\r
}\r
else{\r
if(x1 == x2){\r
}\r
break;\r
case 6:\r
- if(a3 == 5){\r
- /* only implimented for gothic\r
- tx1 = x4 - kage.kMage;\r
- ty1 = y4;\r
- tx2 = x4 + kage.kMage * 0.5;\r
- ty2 = y4 - kage.kMage * 2;\r
- */\r
+ if(a3 == 4){\r
+ if(x3 == x4){\r
+ tx1 = x4;\r
+ ty1 = y4 - kage.kMage;\r
+ }\r
+ else if(y3 == y4){\r
+ tx1 = x4 - kage.kMage;\r
+ ty1 = y4;\r
+ }\r
+ else{\r
+ rad = Math.atan((y4 - y3) / (x4 - x3));\r
+ if(x3 < x4){ v = 1; } else{ v = -1; }\r
+ tx1 = x4 - kage.kMage * Math.cos(rad) * v;\r
+ ty1 = y4 - kage.kMage * Math.sin(rad) * v;\r
+ }\r
+ cdDrawBezier(kage, polygons, x1, y1, x2, y2, x3, y3, tx1, ty1, a2, 1);\r
+ cdDrawCurve(kage, polygons, tx1, ty1, x4, y4, x4 - kage.kMage, y4, 1, 14);\r
+ }\r
+ else if(a3 == 5){\r
cdDrawBezier(kage, polygons, x1, y1, x2, y2, x3, y3, x4, y4, a2, 15);\r
- /*\r
- if(a2 == 7 || a3 == 7){\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 17);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 17, 15);\r
- }\r
- else{\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 8);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, 15);\r
- }\r
- */\r
}\r
else{\r
- cdDrawBezier(kage, polygons, x1, y1, x2, y2, x3, y3, x4, y4, a2, a3);\r
- /*\r
- if(a2 == 7 || a3 == 7){\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 17);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 17, a3);\r
- }\r
- else{\r
- cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 8);\r
- cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, a3);\r
- }\r
- */\r
+ cdDrawCurve(kage, polygons, x1, y1, x2, y2, x3, y3, x4, y4, a2, a3);\r
}\r
break;\r
case 7:\r
// resolution : 0.1\r
\r
// method\r
- function push(x, y){ // void\r
+ function push(x, y, off){ // void\r
var temp = new Object();\r
temp.x = Math.floor(x*10)/10;\r
temp.y = Math.floor(y*10)/10;\r
+ if(off != 1){\r
+ off = 0;\r
+ }\r
+ temp.off = off;\r
this.array.push(temp);\r
}\r
Polygon.prototype.push = push;\r
\r
- function set(index, x, y){ // void\r
+ function set(index, x, y, off){ // void\r
this.array[index].x = Math.floor(x*10)/10;\r
this.array[index].y = Math.floor(y*10)/10;\r
+ if(off != 1){\r
+ off = 0;\r
+ }\r
+ this.array[index].off = off;\r
}\r
Polygon.prototype.set = set;\r
\r
}\r
Polygon.prototype.shift = shift;\r
\r
- function unshift(x, y){ // void\r
+ function unshift(x, y, off){ // void\r
var temp = new Object();\r
temp.x = Math.floor(x*10)/10;\r
temp.y = Math.floor(y*10)/10;\r
+ if(off != 1){\r
+ off = 0;\r
+ }\r
+ temp.off = off;\r
this.array.unshift(temp);\r
}\r
Polygon.prototype.unshift = unshift;\r
// initialize\r
if(number){\r
for(var i = 0; i < number; i++){\r
- this.push(0, 0);\r
+ this.push(0, 0, 0);\r
}\r
}\r
\r
newArray.push(polygon.array.shift());\r
while(polygon.array.length != 0){\r
var temp = polygon.array.shift();\r
- if(newArray[newArray.length - 1].x != temp.x ||\r
- newArray[newArray.length - 1].y != temp.y){\r
+ //if(newArray[newArray.length - 1].x != temp.x ||\r
+ // newArray[newArray.length - 1].y != temp.y){\r
newArray.push(temp);\r
- }\r
+ //}\r
}\r
if(newArray.length >= 3){\r
polygon.array = newArray;\r
}\r
Polygons.prototype.push = push;\r
\r
- function generateSVG(){ // string\r
+ function generateSVG(curve){ // string\r
var buffer = "";\r
- buffer += "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" baseProfile=\"full\" viewBox=\"0 0 199 199\">\n";\r
- buffer += "<g fill=\"black\">\n";\r
- for(var i = 0; i < this.array.length; i++){\r
- buffer += "<polygon points=\"";\r
- for(var j = 0; j < this.array[i].array.length; j++){\r
- buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";\r
+ buffer += "<svg xmlns=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" version=\"1.1\" baseProfile=\"full\" viewBox=\"0 0 200 200\" width=\"200\" height=\"200\">\n";\r
+ if(curve){\r
+ for(var i = 0; i < this.array.length; i++){\r
+ var mode = "L";\r
+ buffer += "<path d=\"M ";\r
+ buffer += this.array[i].array[0].x + "," + this.array[i].array[0].y + " ";\r
+ for(var j = 1; j < this.array[i].array.length; j++){\r
+ if(this.array[i].array[j].off == 1){\r
+ buffer += "Q ";\r
+ mode = "Q";\r
+ } else if(mode == "Q" && this.array[i].array[j - 1].off != 1){\r
+ buffer += "L ";\r
+ } else if(mode == "L" && j == 1){\r
+ buffer += "L ";\r
+ }\r
+ buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";\r
+ }\r
+ buffer += "Z\" fill=\"black\" />\n";\r
+ }\r
+ buffer += "</svg>\n";\r
+ } else {\r
+ buffer += "<g fill=\"black\">\n";\r
+ for(var i = 0; i < this.array.length; i++){\r
+ buffer += "<polygon points=\"";\r
+ for(var j = 0; j < this.array[i].array.length; j++){\r
+ buffer += this.array[i].array[j].x + "," + this.array[i].array[j].y + " ";\r
+ }\r
+ buffer += "\" />\n";\r
}\r
- buffer += "\" />\n";\r
+ buffer += "</g>\n";\r
+ buffer += "</svg>\n";\r
}\r
- buffer += "</g>\n";\r
- buffer += "</svg>\n";\r
return buffer;\r
}\r
Polygons.prototype.generateSVG = generateSVG;\r
<head>\r
<script type="text/javascript" src="2d.js"></script>\r
<script type="text/javascript" src="buhin.js"></script>\r
+ <script type="text/javascript" src="curve.js"></script>\r
<script type="text/javascript" src="kage.js"></script>\r
<script type="text/javascript" src="kagecd.js"></script>\r
<script type="text/javascript" src="kagedf.js"></script>\r
load("2d.js");
load("buhin.js");
+load("curve.js");
load("kage.js");
load("kagecd.js");
load("kagedf.js");
load("polygons.js");
var kage = new Kage();
+kage.kUseCurve = true;
var polygons = new Polygons();
kage.kBuhin.push("u6f22", "99:0:0:9:12:73:200:u6c35-07$99:0:0:54:10:190:199:u26c29-07");
kage.makeGlyph(polygons, "u6f22");
-print(polygons.generateSVG());
+print(polygons.generateSVG(true));