From: Koichi KAMICHI Date: Tue, 25 Aug 2009 12:13:46 +0000 (+0000) Subject: Updated. Add new curve script. X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=56ba2717831bb2d60440ef2f3de610887a1b7058;p=chise%2Fkage.git Updated. Add new curve script. --- diff --git a/engine/curve.js b/engine/curve.js new file mode 100644 index 0000000..01bf840 --- /dev/null +++ b/engine/curve.js @@ -0,0 +1,192 @@ +function divide_curve(kage, x1, y1, sx1, sy1, x2, y2, curve, div_curve, off_curve){ + var rate = 0.5; + var cut = Math.floor(curve.length * rate); + var cut_rate = cut / curve.length; + var tx1 = x1 + (sx1 - x1) * cut_rate; + var ty1 = y1 + (sy1 - y1) * cut_rate; + var tx2 = sx1 + (x2 - sx1) * cut_rate; + var ty2 = sy1 + (y2 - sy1) * cut_rate; + var tx3 = tx1 + (tx2 - tx1) * cut_rate; + var ty3 = ty1 + (ty2 - ty1) * cut_rate; + + div_curve[0] = new Array(); + div_curve[1] = new Array(); + off_curve[0] = new Array(6); + off_curve[1] = new Array(6); + + // must think about 0 : <0 + var i; + for(i = 0; i <= cut; i++){ + div_curve[0].push(curve[i]); + } + off_curve[0][0] = x1; + off_curve[0][1] = y1; + off_curve[0][2] = tx1; + off_curve[0][3] = ty1; + off_curve[0][4] = tx3; + off_curve[0][5] = ty3; + + for(i = cut; i < curve.length; i++){ + div_curve[1].push(curve[i]); + } + off_curve[1][0] = tx3; + off_curve[1][1] = ty3; + off_curve[1][2] = tx2; + off_curve[1][3] = ty2; + off_curve[1][4] = x2; + off_curve[1][5] = y2; +} + +// ------------------------------------------------------------------ +function find_offcurve(kage, curve, sx, sy, result){ + var nx1, ny1, nx2, ny2, tx, ty; + var minx, miny, count, diff; + var tt, t, x, y, ix, iy; + var mindiff = 100000; + var area = 8; + var mesh = 2; + // area = 10 mesh = 5 -> 281 calcs + // area = 10 mesh = 4 -> 180 calcs + // area = 8 mesh = 4 -> 169 calcs + // area = 7.5 mesh = 3 -> 100 calcs + // area = 8 mesh = 2 -> 97 calcs + // area = 7 mesh = 2 -> 80 calcs + + nx1 = curve[0][0]; + ny1 = curve[0][1]; + nx2 = curve[curve.length - 1][0]; + ny2 = curve[curve.length - 1][1]; + + for(tx = sx - area; tx < sx + area; tx += mesh){ + for(ty = sy - area; ty < sy + area; ty += mesh){ + count = 0; + diff = 0; + for(tt = 0; tt < curve.length; tt++){ + t = tt / curve.length; + + //calculate a dot + x = ((1.0 - t) * (1.0 - t) * nx1 + 2.0 * t * (1.0 - t) * tx + t * t * nx2); + y = ((1.0 - t) * (1.0 - t) * ny1 + 2.0 * t * (1.0 - t) * ty + t * t * ny2); + + //KATAMUKI of vector by BIBUN + ix = (nx1 - 2.0 * tx + nx2) * 2.0 * t + (-2.0 * nx1 + 2.0 * tx); + iy = (ny1 - 2.0 * ty + ny2) * 2.0 * t + (-2.0 * ny1 + 2.0 * ty); + + diff += (curve[count][0] - x) * (curve[count][0] - x) + (curve[count][1] - y) * (curve[count][1] - y); + if(diff > mindiff){ + tt = curve.length; + } + count++; + } + if(diff < mindiff){ + minx = tx; + miny = ty; + mindiff = diff; + } + } + } + + for(tx = minx - mesh + 1; tx <= minx + mesh - 1; tx += 0.5){ + for(ty = miny - mesh + 1; ty <= miny + mesh - 1; ty += 0.5){ + count = 0; + diff = 0; + for(tt = 0; tt < curve.length; tt++){ + t = tt / curve.length; + + //calculate a dot + x = ((1.0 - t) * (1.0 - t) * nx1 + 2.0 * t * (1.0 - t) * tx + t * t * nx2); + y = ((1.0 - t) * (1.0 - t) * ny1 + 2.0 * t * (1.0 - t) * ty + t * t * ny2); + + //KATAMUKI of vector by BIBUN + ix = (nx1 - 2.0 * tx + nx2) * 2.0 * t + (-2.0 * nx1 + 2.0 * tx); + iy = (ny1 - 2.0 * ty + ny2) * 2.0 * t + (-2.0 * ny1 + 2.0 * ty); + + diff += (curve[count][0] - x) * (curve[count][0] - x) + (curve[count][1] - y) * (curve[count][1] - y); + if(diff > mindiff){ + tt = curve.length; + } + count++; + } + if(diff < mindiff){ + minx = tx; + miny = ty; + mindiff = diff; + } + } + } + + result[0] = nx1; + result[1] = ny1; + result[2] = minx; + result[3] = miny; + result[4] = nx2; + result[5] = ny2; + result[6] = mindiff; +} + +// ------------------------------------------------------------------ +function get_candidate(kage, curve, a1, a2, x1, y1, sx1, sy1, x2, y2){ + var x, y, ix, iy, ir, ia, ib, tt, t, deltad; + var hosomi = 0.5; + + curve[0] = new Array(); + curve[1] = new Array(); + + for(tt = 0; tt <= 1000; tt = tt + kage.kRate){ + t = tt / 1000; + + //calculate a dot + x = ((1.0 - t) * (1.0 - t) * x1 + 2.0 * t * (1.0 - t) * sx1 + t * t * x2); + y = ((1.0 - t) * (1.0 - t) * y1 + 2.0 * t * (1.0 - t) * sy1 + t * t * y2); + + //KATAMUKI of vector by BIBUN + ix = (x1 - 2.0 * sx1 + x2) * 2.0 * t + (-2.0 * x1 + 2.0 * sx1); + iy = (y1 - 2.0 * sy1 + y2) * 2.0 * t + (-2.0 * y1 + 2.0 * sy1); + //line SUICHOKU by vector + if(ix != 0 && iy != 0){ + ir = Math.atan(iy / ix * -1); + ia = Math.sin(ir) * (kage.kMinWidthT); + ib = Math.cos(ir) * (kage.kMinWidthT); + } + else if(ix == 0){ + ia = kage.kMinWidthT; + ib = 0; + } + else{ + ia = 0; + ib = kage.kMinWidthT; + } + + if(a1 == 7 && a2 == 0){ // L2RD: fatten + deltad = Math.pow(t, hosomi) * kage.kL2RDfatten; + } + else if(a1 == 7){ + deltad = Math.pow(t, hosomi); + } + else if(a2 == 7){ + deltad = Math.pow(1.0 - t, hosomi); + } + else{ deltad = 1; } + + if(deltad < 0.15){ + deltad = 0.15; + } + ia = ia * deltad; + ib = ib * deltad; + + //reverse if vector is going 2nd/3rd quadrants + if(ix <= 0){ + ia = ia * -1; + ib = ib * -1; + } + + temp = new Array(2); + temp[0] = x - ia; + temp[1] = y - ib; + curve[0].push(temp); + temp = new Array(2); + temp[0] = x + ia; + temp[1] = y + ib; + curve[1].push(temp); + } +} diff --git a/engine/kage.js b/engine/kage.js index bc97a5a..0fe9bdc 100755 --- a/engine/kage.js +++ b/engine/kage.js @@ -222,6 +222,7 @@ function Kage(){ this.kKakato = 3; this.kL2RDfatten = 1.1; this.kMage = 10; + this.kUseCurve = 0; this.kAdjustKakatoL = ([14, 9, 5, 2]); // for KAKATO adjustment 000,100,200,300 this.kAdjustKakatoR = ([8, 6, 4, 2]); // for KAKATO adjustment 000,100,200,300 diff --git a/engine/kagecd.js b/engine/kagecd.js index 7d70e96..c8e3fc6 100755 --- a/engine/kagecd.js +++ b/engine/kagecd.js @@ -83,98 +83,212 @@ function cdDrawCurveU(kage, polygons, x1, y1, sx1, sy1, sx2, sy2, x2, y2, a1, a2 hosomi += 0.4 * (1 - Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1)) / 50); } + //--------------------------------------------------------------- + poly = new Polygon(); poly2 = new Polygon(); - for(tt = 0; tt <= 1000; tt = tt + kage.kRate){ - t = tt / 1000; - - if(sx1 == sx2 && sy1 == sy2){ // Spline - //calculate a dot - x = ((1.0 - t) * (1.0 - t) * x1 + 2.0 * t * (1.0 - t) * sx1 + t * t * x2); - y = ((1.0 - t) * (1.0 - t) * y1 + 2.0 * t * (1.0 - t) * sy1 + t * t * y2); + if(sx1 == sx2 && sy1 == sy2){ // Spline + if(kage.kUseCurve){ + // generating fatten curve -- begin + var kage2 = new Kage(); + kage2.kRate = 10; - //KATAMUKI of vector by BIBUN - ix = (x1 - 2.0 * sx1 + x2) * 2.0 * t + (-2.0 * x1 + 2.0 * sx1); - iy = (y1 - 2.0 * sy1 + y2) * 2.0 * t + (-2.0 * y1 + 2.0 * sy1); - } else { // Bezier - //calculate a dot + var curve = new Array(2); // L and R + get_candidate(kage2, curve, a1, a2, x1, y1, sx1, sy1, x2, y2); + + var dcl12_34 = new Array(2); + var dcr12_34 = new Array(2); + var dpl12_34 = new Array(2); + var dpr12_34 = new Array(2); + divide_curve(kage2, x1, y1, sx1, sy1, x2, y2, curve[0], dcl12_34, dpl12_34); + divide_curve(kage2, x1, y1, sx1, sy1, x2, y2, curve[1], dcr12_34, dpr12_34); + + var ncl1 = new Array(7); + var ncl2 = new Array(7); + find_offcurve(kage2, dcl12_34[0], dpl12_34[0][2], dpl12_34[0][3], ncl1); + find_offcurve(kage2, dcl12_34[1], dpl12_34[1][2], dpl12_34[1][3], ncl2); + + poly.push(ncl1[0], ncl1[1]); + poly.push(ncl1[2], ncl1[3], 1); + poly.push(ncl1[4], ncl1[5]); + poly.push(ncl2[2], ncl2[3], 1); + poly.push(ncl2[4], ncl2[5]); + + poly2.push(dcr12_34[0][0][0], dcr12_34[0][0][1]); + poly2.push(dpr12_34[0][2] - (ncl1[2] - dpl12_34[0][2]), dpl12_34[0][3] - (ncl1[3] - dpl12_34[0][3]), 1); + poly2.push(dcr12_34[0][dcr12_34[0].length - 1][0], dcr12_34[0][dcr12_34[0].length - 1][1]); + poly2.push(dpr12_34[1][2] - (ncl2[2] - dpl12_34[1][2]), dpl12_34[1][3] - (ncl2[3] - dpl12_34[1][3]), 1); + poly2.push(dcr12_34[1][dcr12_34[1].length - 1][0], dcr12_34[1][dcr12_34[1].length - 1][1]); + + poly2.reverse(); + poly.concat(poly2); + polygons.push(poly); + // generating fatten curve -- end + } else { + for(tt = 0; tt <= 1000; tt = tt + kage.kRate){ + t = tt / 1000; + + // calculate a dot + x = ((1.0 - t) * (1.0 - t) * x1 + 2.0 * t * (1.0 - t) * sx1 + t * t * x2); + y = ((1.0 - t) * (1.0 - t) * y1 + 2.0 * t * (1.0 - t) * sy1 + t * t * y2); + + // KATAMUKI of vector by BIBUN + ix = (x1 - 2.0 * sx1 + x2) * 2.0 * t + (-2.0 * x1 + 2.0 * sx1); + iy = (y1 - 2.0 * sy1 + y2) * 2.0 * t + (-2.0 * y1 + 2.0 * sy1); + + // line SUICHOKU by vector + if(ix != 0 && iy != 0){ + ir = Math.atan(iy / ix * -1); + ia = Math.sin(ir) * (kage.kMinWidthT); + ib = Math.cos(ir) * (kage.kMinWidthT); + } + else if(ix == 0){ + ia = kage.kMinWidthT; + ib = 0; + } + else{ + ia = 0; + ib = kage.kMinWidthT; + } + + if(a1 == 7 && a2 == 0){ // L2RD: fatten + deltad = Math.pow(t, hosomi) * kage.kL2RDfatten; + } + else if(a1 == 7){ + deltad = Math.pow(t, hosomi); + } + else if(a2 == 7){ + deltad = Math.pow(1.0 - t, hosomi); + } + else{ deltad = 1; } + + if(deltad < 0.15){ + deltad = 0.15; + } + ia = ia * deltad; + ib = ib * deltad; + + //reverse if vector is going 2nd/3rd quadrants + if(ix <= 0){ + ia = ia * -1; + ib = ib * -1; + } + + //copy to polygon structure + poly.push(x - ia, y - ib); + poly2.push(x + ia, y + ib); + } + + // suiheisen ni setsuzoku + if(a1 == 132){ + var index = 0; + while(true){ + if(poly2.array[index].y <= y1 && y1 <= poly2.array[index + 1].y){ + break; + } + index++; + } + newx1 = poly2.array[index + 1].x + (poly2.array[index].x - poly2.array[index + 1].x) * + (poly2.array[index + 1].y - y1) / (poly2.array[index + 1].y - poly2.array[index].y); + newy1 = y1; + newx2 = poly.array[0].x + (poly.array[0].x - poly.array[1].x) * (poly.array[0].y - y1) / + (poly.array[1].y - poly.array[0].y); + newy2 = y1; + + for(var i = 0; i < index; i++){ + poly2.shift(); + } + poly2.set(0, newx1, newy1); + poly.unshift(newx2, newy2); + } + + poly2.reverse(); + poly.concat(poly2); + polygons.push(poly); + } + } else { // Bezier + for(tt = 0; tt <= 1000; tt = tt + kage.kRate){ + t = tt / 1000; + + // calculate a dot 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; 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; - //KATAMUKI of vector by BIBUN + // KATAMUKI of vector by BIBUN ix = t * t * (-3 * x1 + 9 * sx1 + -9 * sx2 + 3 * x2) + t * (6 * x1 + -12 * sx1 + 6 * sx2) + -3 * x1 + 3 * sx1; iy = t * t * (-3 * y1 + 9 * sy1 + -9 * sy2 + 3 * y2) + t * (6 * y1 + -12 * sy1 + 6 * sy2) + -3 * y1 + 3 * sy1; - } - //line SUICHOKU by vector - if(ix != 0 && iy != 0){ - ir = Math.atan(iy / ix * -1); - ia = Math.sin(ir) * (kage.kMinWidthT); - ib = Math.cos(ir) * (kage.kMinWidthT); - } - else if(ix == 0){ - ia = kage.kMinWidthT; - ib = 0; - } - else{ - ia = 0; - ib = kage.kMinWidthT; - } - - if(a1 == 7 && a2 == 0){ // L2RD: fatten - deltad = Math.pow(t, hosomi) * kage.kL2RDfatten; - } - else if(a1 == 7){ - deltad = Math.pow(t, hosomi); - } - else if(a2 == 7){ - deltad = Math.pow(1.0 - t, hosomi); - } - else{ deltad = 1; } - - if(deltad < 0.15){ - deltad = 0.15; - } - ia = ia * deltad; - ib = ib * deltad; - - //reverse if vector is going 2nd/3rd quadrants - if(ix <= 0){ - ia = ia * -1; - ib = ib * -1; + + // line SUICHOKU by vector + if(ix != 0 && iy != 0){ + ir = Math.atan(iy / ix * -1); + ia = Math.sin(ir) * (kage.kMinWidthT); + ib = Math.cos(ir) * (kage.kMinWidthT); + } + else if(ix == 0){ + ia = kage.kMinWidthT; + ib = 0; + } + else{ + ia = 0; + ib = kage.kMinWidthT; + } + + if(a1 == 7 && a2 == 0){ // L2RD: fatten + deltad = Math.pow(t, hosomi) * kage.kL2RDfatten; + } + else if(a1 == 7){ + deltad = Math.pow(t, hosomi); + } + else if(a2 == 7){ + deltad = Math.pow(1.0 - t, hosomi); + } + else{ deltad = 1; } + + if(deltad < 0.15){ + deltad = 0.15; + } + ia = ia * deltad; + ib = ib * deltad; + + //reverse if vector is going 2nd/3rd quadrants + if(ix <= 0){ + ia = ia * -1; + ib = ib * -1; + } + + //copy to polygon structure + poly.push(x - ia, y - ib); + poly2.push(x + ia, y + ib); } - //copy to polygon structure - poly.push(x - ia, y - ib); - poly2.push(x + ia, y + ib); - } - - // suiheisen ni setsuzoku - if(a1 == 132){ - var index = 0; - while(true){ - if(poly2.array[index].y <= y1 && y1 <= poly2.array[index + 1].y){ - break; + // suiheisen ni setsuzoku + if(a1 == 132){ + var index = 0; + while(true){ + if(poly2.array[index].y <= y1 && y1 <= poly2.array[index + 1].y){ + break; + } + index++; + } + newx1 = poly2.array[index + 1].x + (poly2.array[index].x - poly2.array[index + 1].x) * + (poly2.array[index + 1].y - y1) / (poly2.array[index + 1].y - poly2.array[index].y); + newy1 = y1; + newx2 = poly.array[0].x + (poly.array[0].x - poly.array[1].x) * (poly.array[0].y - y1) / + (poly.array[1].y - poly.array[0].y); + newy2 = y1; + + for(var i = 0; i < index; i++){ + poly2.shift(); } - index++; + poly2.set(0, newx1, newy1); + poly.unshift(newx2, newy2); } - newx1 = poly2.array[index + 1].x + (poly2.array[index].x - poly2.array[index + 1].x) * - (poly2.array[index + 1].y - y1) / (poly2.array[index + 1].y - poly2.array[index].y); - newy1 = y1; - newx2 = poly.array[0].x + (poly.array[0].x - poly.array[1].x) * (poly.array[0].y - y1) / - (poly.array[1].y - poly.array[0].y); - newy2 = y1; - for(var i = 0; i < index; i++){ - poly2.shift(); - } - poly2.set(0, newx1, newy1); - poly.unshift(newx2, newy2); + poly2.reverse(); + poly.concat(poly2); + polygons.push(poly); } - poly2.reverse(); - poly.concat(poly2); - polygons.push(poly); - //process for head of stroke rad = Math.atan((sy1 - y1) / (sx1 - x1)); if(x1 < sx1){ v = 1; } else{ v = -1; } @@ -311,31 +425,61 @@ function cdDrawCurveU(kage, polygons, x1, y1, sx1, sy1, sx2, sy2, x2, y2, a1, a2 if(a2 == 1 || a2 == 8 || a2 == 15){ //the last filled circle ... it can change 15->5 if(sx2 == x2){ poly = new Polygon(); - poly.push(x2 - kage.kMinWidthT, y2); - poly.push(x2 - kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7); - poly.push(x2, y2 + kage.kMinWidthT); - poly.push(x2 + kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7); - poly.push(x2 + kage.kMinWidthT, y2); + if(kage.kUseCurve){ + // by curve path + poly.push(x2 - kage.kMinWidthT, y2); + poly.push(x2 - kage.kMinWidthT, y2 + kage.kMinWidthT, 1); + poly.push(x2, y2 + kage.kMinWidthT); + poly.push(x2 + kage.kMinWidthT, y2 + kage.kMinWidthT, 1); + poly.push(x2 + kage.kMinWidthT, y2); + } else { + // by polygon + poly.push(x2 - kage.kMinWidthT, y2); + poly.push(x2 - kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7); + poly.push(x2, y2 + kage.kMinWidthT); + poly.push(x2 + kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7); + poly.push(x2 + kage.kMinWidthT, y2); + } polygons.push(poly); } else if(sy2 == y2){ poly = new Polygon(); - poly.push(x2, y2 - kage.kMinWidthT); - poly.push(x2 + kage.kMinWidthT * 0.7, y2 - kage.kMinWidthT * 0.7); - poly.push(x2 + kage.kMinWidthT, y2); - poly.push(x2 + kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7); - poly.push(x2, y2 + kage.kMinWidthT); + if(kage.kUseCurve){ + // by curve path + poly.push(x2 - kage.kMinWidthT, y2); + poly.push(x2 - kage.kMinWidthT, y2 + kage.kMinWidthT, 1); + poly.push(x2, y2 + kage.kMinWidthT); + poly.push(x2 + kage.kMinWidthT, y2 + kage.kMinWidthT, 1); + poly.push(x2 + kage.kMinWidthT, y2); + } else { + // by polygon + poly.push(x2, y2 - kage.kMinWidthT); + poly.push(x2 + kage.kMinWidthT * 0.7, y2 - kage.kMinWidthT * 0.7); + poly.push(x2 + kage.kMinWidthT, y2); + poly.push(x2 + kage.kMinWidthT * 0.7, y2 + kage.kMinWidthT * 0.7); + poly.push(x2, y2 + kage.kMinWidthT); + } polygons.push(poly); } else{ poly = new Polygon(); - poly.push(x2 + Math.sin(rad) * kage.kMinWidthT * v, y2 - Math.cos(rad) * kage.kMinWidthT * v); - poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.7 * v + Math.sin(rad) * kage.kMinWidthT * 0.7 * v, - y2 + Math.sin(rad) * kage.kMinWidthT * 0.7 * v - Math.cos(rad) * kage.kMinWidthT * 0.7 * v); - poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * v, y2 + Math.sin(rad) * kage.kMinWidthT * v); - poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.7 * v - Math.sin(rad) * kage.kMinWidthT * 0.7 * v, - y2 + Math.sin(rad) * kage.kMinWidthT * 0.7 * v + Math.cos(rad) * kage.kMinWidthT * 0.7 * v); - poly.push(x2 - Math.sin(rad) * kage.kMinWidthT * v, y2 + Math.cos(rad) * kage.kMinWidthT * v); + if(kage.kUseCurve){ + poly.push(x2 + Math.sin(rad) * kage.kMinWidthT * v, y2 - Math.cos(rad) * kage.kMinWidthT * v); + poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.9 * v + Math.sin(rad) * kage.kMinWidthT * 0.9 * v, + y2 + Math.sin(rad) * kage.kMinWidthT * 0.9 * v - Math.cos(rad) * kage.kMinWidthT * 0.9 * v, 1); + poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * v, y2 + Math.sin(rad) * kage.kMinWidthT * v); + poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.9 * v - Math.sin(rad) * kage.kMinWidthT * 0.9 * v, + y2 + Math.sin(rad) * kage.kMinWidthT * 0.9 * v + Math.cos(rad) * kage.kMinWidthT * 0.9 * v, 1); + poly.push(x2 - Math.sin(rad) * kage.kMinWidthT * v, y2 + Math.cos(rad) * kage.kMinWidthT * v); + } else { + poly.push(x2 + Math.sin(rad) * kage.kMinWidthT * v, y2 - Math.cos(rad) * kage.kMinWidthT * v); + poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.7 * v + Math.sin(rad) * kage.kMinWidthT * 0.7 * v, + y2 + Math.sin(rad) * kage.kMinWidthT * 0.7 * v - Math.cos(rad) * kage.kMinWidthT * 0.7 * v); + poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * v, y2 + Math.sin(rad) * kage.kMinWidthT * v); + poly.push(x2 + Math.cos(rad) * kage.kMinWidthT * 0.7 * v - Math.sin(rad) * kage.kMinWidthT * 0.7 * v, + y2 + Math.sin(rad) * kage.kMinWidthT * 0.7 * v + Math.cos(rad) * kage.kMinWidthT * 0.7 * v); + poly.push(x2 - Math.sin(rad) * kage.kMinWidthT * v, y2 + Math.cos(rad) * kage.kMinWidthT * v); + } polygons.push(poly); } } diff --git a/engine/kagedf.js b/engine/kagedf.js index b7a826d..a5c34bf 100755 --- a/engine/kagedf.js +++ b/engine/kagedf.js @@ -92,14 +92,14 @@ function dfDrawFont(kage, polygons, a1, a2, a3, x1, y1, x2, y2, x3, y3, x4, y4){ tx2 = x2 + kage.kMage * Math.cos(rad) * v; ty2 = y2 + kage.kMage * Math.sin(rad) * v; } - tx3 = x3; + tx3 = x3; ty3 = y3; cdDrawLine(kage, polygons, x1, y1, tx1, ty1, a2, 1); cdDrawCurve(kage, polygons, tx1, ty1, x2, y2, tx2, ty2, 1, 1); - if(tx3 - tx2 > 0){ // for closer position - cdDrawLine(kage, polygons, tx2, ty2, tx3, ty3, 6, 5); // bolder by force - } + if(tx3 - tx2 > 0){ // for closer position + cdDrawLine(kage, polygons, tx2, ty2, tx3, ty3, 6, 5); // bolder by force + } } else{ if(x1 == x2){ @@ -229,37 +229,29 @@ function dfDrawFont(kage, polygons, a1, a2, a3, x1, y1, x2, y2, x3, y3, x4, y4){ } break; case 6: - if(a3 == 5){ - /* only implimented for gothic - tx1 = x4 - kage.kMage; - ty1 = y4; - tx2 = x4 + kage.kMage * 0.5; - ty2 = y4 - kage.kMage * 2; - */ + if(a3 == 4){ + if(x3 == x4){ + tx1 = x4; + ty1 = y4 - kage.kMage; + } + else if(y3 == y4){ + tx1 = x4 - kage.kMage; + ty1 = y4; + } + else{ + rad = Math.atan((y4 - y3) / (x4 - x3)); + if(x3 < x4){ v = 1; } else{ v = -1; } + tx1 = x4 - kage.kMage * Math.cos(rad) * v; + ty1 = y4 - kage.kMage * Math.sin(rad) * v; + } + cdDrawBezier(kage, polygons, x1, y1, x2, y2, x3, y3, tx1, ty1, a2, 1); + cdDrawCurve(kage, polygons, tx1, ty1, x4, y4, x4 - kage.kMage, y4, 1, 14); + } + else if(a3 == 5){ cdDrawBezier(kage, polygons, x1, y1, x2, y2, x3, y3, x4, y4, a2, 15); - /* - if(a2 == 7 || a3 == 7){ - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 17); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 17, 15); - } - else{ - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 8); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, 15); - } - */ } else{ - cdDrawBezier(kage, polygons, x1, y1, x2, y2, x3, y3, x4, y4, a2, a3); - /* - if(a2 == 7 || a3 == 7){ - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 17); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 17, a3); - } - else{ - cdDrawCurve(x1, y1, x2, y2, (x2 + x3) / 2, (y2 + y3) / 2, a2, 8); - cdDrawCurve((x2 + x3) / 2, (y2 + y3) / 2, x3, y3, x4, y4, 1, a3); - } - */ + cdDrawCurve(kage, polygons, x1, y1, x2, y2, x3, y3, x4, y4, a2, a3); } break; case 7: diff --git a/engine/polygon.js b/engine/polygon.js index c232460..4d26b38 100755 --- a/engine/polygon.js +++ b/engine/polygon.js @@ -2,17 +2,25 @@ function Polygon(number){ // resolution : 0.1 // method - function push(x, y){ // void + function push(x, y, off){ // void var temp = new Object(); temp.x = Math.floor(x*10)/10; temp.y = Math.floor(y*10)/10; + if(off != 1){ + off = 0; + } + temp.off = off; this.array.push(temp); } Polygon.prototype.push = push; - function set(index, x, y){ // void + function set(index, x, y, off){ // void this.array[index].x = Math.floor(x*10)/10; this.array[index].y = Math.floor(y*10)/10; + if(off != 1){ + off = 0; + } + this.array[index].off = off; } Polygon.prototype.set = set; @@ -31,10 +39,14 @@ function Polygon(number){ } Polygon.prototype.shift = shift; - function unshift(x, y){ // void + function unshift(x, y, off){ // void var temp = new Object(); temp.x = Math.floor(x*10)/10; temp.y = Math.floor(y*10)/10; + if(off != 1){ + off = 0; + } + temp.off = off; this.array.unshift(temp); } Polygon.prototype.unshift = unshift; @@ -45,7 +57,7 @@ function Polygon(number){ // initialize if(number){ for(var i = 0; i < number; i++){ - this.push(0, 0); + this.push(0, 0, 0); } } diff --git a/engine/polygons.js b/engine/polygons.js index 74f2907..75ebdc1 100755 --- a/engine/polygons.js +++ b/engine/polygons.js @@ -34,10 +34,10 @@ function Polygons(){ newArray.push(polygon.array.shift()); while(polygon.array.length != 0){ var temp = polygon.array.shift(); - if(newArray[newArray.length - 1].x != temp.x || - newArray[newArray.length - 1].y != temp.y){ + //if(newArray[newArray.length - 1].x != temp.x || + // newArray[newArray.length - 1].y != temp.y){ newArray.push(temp); - } + //} } if(newArray.length >= 3){ polygon.array = newArray; @@ -47,19 +47,40 @@ function Polygons(){ } Polygons.prototype.push = push; - function generateSVG(){ // string + function generateSVG(curve){ // string var buffer = ""; - buffer += "\n"; - buffer += "\n"; - for(var i = 0; i < this.array.length; i++){ - buffer += "\n"; + if(curve){ + for(var i = 0; i < this.array.length; i++){ + var mode = "L"; + buffer += "\n"; + } + buffer += "\n"; + } else { + buffer += "\n"; + for(var i = 0; i < this.array.length; i++){ + buffer += "\n"; } - buffer += "\" />\n"; + buffer += "\n"; + buffer += "\n"; } - buffer += "\n"; - buffer += "\n"; return buffer; } Polygons.prototype.generateSVG = generateSVG; diff --git a/engine/sample.html b/engine/sample.html index f8825f9..de9c06a 100644 --- a/engine/sample.html +++ b/engine/sample.html @@ -2,6 +2,7 @@ + diff --git a/engine/sample.js b/engine/sample.js index 319599f..271f668 100644 --- a/engine/sample.js +++ b/engine/sample.js @@ -5,6 +5,7 @@ load("2d.js"); load("buhin.js"); +load("curve.js"); load("kage.js"); load("kagecd.js"); load("kagedf.js"); @@ -12,6 +13,7 @@ load("polygon.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"); @@ -20,5 +22,5 @@ kage.kBuhin.push("u26c29-07", "1:0:0:18:29:187:29$1:0:0:73:10:73:48$1:0:0:132:10 kage.makeGlyph(polygons, "u6f22"); -print(polygons.generateSVG()); +print(polygons.generateSVG(true));