-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
761 lines (683 loc) · 21.3 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
<!-- ファイル index_skirt.html -->
<!--
This file is licensed under CC0.
http://creativecommons.org/publicdomain/zero/1.0/deed.ja
-->
<html>
<head>
<meta charset="utf-8"/>
<title>紙プリーツスカート生成器</title>
<style>
#theCanvas {
border-style: solid;
visibility: hidden;
}
#theImage {
border-style: solid;
}
</style>
</head>
<body>
<h1>紙プリーツスカート生成器</h1>
<h2>使い方</h2>
<ol>
<li>パラメータ (単位はピクセル) を入力し、「生成」ボタンを押します。</li>
<li>ページ下に表示された画像を印刷します。</li>
<li>切り抜いて組み立てます。</li>
</ol>
<h2>パラメータ</h2>
<form id="theForm">
<p>
<input type="radio" name="pleatsType" id="KnifePleatsRadio" value="KnifePleats" checked>車ヒダ
<input type="radio" name="pleatsType" id="FrontBoxPleatsRadio" value="FrontBoxPleats">前箱ヒダ
<input type="radio" name="pleatsType" id="InvertedPleatsRadio" value="InvertedPleats">箱ヒダ
</p>
<p>
<table>
<tr>
<td>ウエスト</td>
<td><input name="ウエスト" type="number" id="waistCirc" min="1" max="9999" value="200"></td>
</tr>
<tr>
<td>すそ周</td>
<td><input name="すそ周" type="number" id="bottomCirc" min="1" max="9999" value="250"></td>
</tr>
<tr>
<td>丈長さ</td>
<td><input name="丈長さ" type="number" id="skirtHeight" min="1" max="9999" value="100"></td>
</tr>
<tr>
<td>プリーツ数</td>
<td><input name="プリーツ数" type="number" id="numPleats" min="2" max="9999" value="16"></td>
</tr>
<tr>
<td>陰プリーツ率</td>
<td><input name="陰プリーツ率" type="number" id="pleatsRatio" min="0.01" max="0.9" value="0.33" step="0.01"></td>
</tr>
<tr>
<td>ベルト幅</td>
<td><input name="ベルト幅" type="number" id="beltHeight" min="0" max="9999" value="15"></td>
</tr>
<tr>
<td>組み立て説明を</td>
<td><input type="checkbox" id="drawInstruction" checked="checked"><label for="drawInstruction">印刷する</label></td>
</tr>
<tr>
<td>稜線強調</td>
<td><input type="checkbox" id="strongLine"><label for="strongLine">する</label></td>
</tr>
<tr>
<td>
</td>
<td>
<input type="button" name="generateButton" value="生成" onclick="OnGenerateButton()">
</td>
<td>
<input type="button" name="resetButton" value="初期化" onclick="OnResetButton()">
</td>
</tr>
</table>
</p>
<p>
</p>
</form>
<div id="theDebug">debug</div>
<canvas id="theCanvas" width="2000" height="2480"></canvas><br>
<img id="theImage">
<script>
///////////////////////////////////////////////////////////////////////////////
var KnifePleats = "KnifePleats";
var FrontBoxPleats = "FrontBoxPleats";
var InvertedPleats = "InvertedPleats";
function PrintDebug(s)
{
var theDebug = document.getElementById("theDebug");
theDebug.textContent = s;
}
function ConvertCanvasToImage()
{
var theCanvas = document.getElementById("theCanvas");
var png = theCanvas.toDataURL();
var theImage = document.getElementById("theImage");
theImage.src = png;
theImage.width = theCanvas.width;
theImage.height = theCanvas.height;
theCanvas.style = "visibility:hidden; width:0px; height:0px;";
}
///角度を ±π の範囲に収める
function NormalizeRadian(r)
{
var n2 = Math.trunc(r / (2*Math.PI));
var q = r - n2 * (2*Math.PI);
if (q > Math.PI) {
q = -(q - Math.PI);
}
else if (q < -Math.PI) {
q = -(q + Math.PI);
}
return q;
}
///作図に必要な範囲を求めるために、2回「描画」する。
///1回目は g_DrawMode=0 にして範囲だけを求めるダミーモード。
///2回目は g_DrawMode=1 にして本当に描画する。
var g_DrawMode = 0;
///作図に必要な範囲。g_DrawMode=0で描画関数を呼ぶたびに更新される。
var g_MinX, g_MinY, g_MaxX, g_MaxY;
function ClearMinMax()
{
g_MinX = g_MinY = 9999;
g_MaxX = g_MaxY = -9999;
}
function DumpMinMax()
{
console.log(g_MinX, g_MinY, g_MaxX, g_MaxY);
}
/// 点(x,y) で作図範囲 g_Min[XY], g_Max[XY] を更新
function AddToMinMax(x, y)
{
g_MinX = Math.min(g_MinX, x);
g_MinY = Math.min(g_MinY, y);
g_MaxX = Math.max(g_MaxX, x);
g_MaxY = Math.max(g_MaxY, y);
}
function AddToMinMaxRect(x, y, w, h)
{
AddToMinMax(x, y);
AddToMinMax(x+w, y+h);
}
function FillRect(x, y, w, h, style)
{
if (g_DrawMode==0) {
AddToMinMaxRect(x, y, w, h);
}
else {
var theCanvas = document.getElementById("theCanvas");
var context = theCanvas.getContext("2d");
context.fillStyle = style;
context.fillRect(x, y, w, h);
}
}
function ClearCanvas(w, h)
{
var theCanvas = document.getElementById("theCanvas");
theCanvas.width = w;
theCanvas.height = h;
FillRect(0, 0, w, h, "#ffffff");
}
function DrawText(s, x, y)
{
var PX = 16;
if (g_DrawMode==0) {
var w = s.length * PX;
var h = PX;
AddToMinMaxRect(x, y, w, h);
}
else {
var theCanvas = document.getElementById("theCanvas");
var context = theCanvas.getContext("2d");
context.strokeStyle = "black";
context.font = PX +"px Arial";
context.textBaseline = 'top';
context.fillText(s, x, y);
}
}
function DrawArc(x, y, r, angle1, angle2, ccw)
{
if (g_DrawMode==0) {
//角度を少しずつ動かしながら位置を求める
var a1 = NormalizeRadian(angle1);
var a2 = NormalizeRadian(angle2);
if (!ccw) {
// 時計回りなら、角度を増やす方向 (a1 < a2)
while (!(a1 < a2)) a2 += 2 * Math.PI;
}
else {
// 反時計周りなら、角度を減らす方向 (a2 < a1)
while (!(a2 < a1)) a2 -= 2 * Math.PI;
}
// 角度 a1 から a2 まで線形補間
var n = r;
for (var i=0; i<=n; i++) {
var t = i / n; // 媒介変数
var a = (1-t) * a1 + t * a2;
var px = x + r * Math.cos(a);
var py = y + r * Math.sin(a);
AddToMinMax(px, py);
}
}
else {
var theCanvas = document.getElementById("theCanvas");
var context = theCanvas.getContext("2d");
context.strokeStyle = "black";
context.lineWidth = IsStrong() ? 2 : 1;
context.beginPath();
context.arc(x, y, r, angle1, angle2, ccw);
context.stroke();
context.closePath();
}
}
function IsStrong() {
return document.getElementById("strongLine").checked;
}
/// @param dash 0=実線, 1=山折り, 2=谷折り
function DrawLine(x1, y1, x2, y2, dash)
{
if (g_DrawMode==0) {
AddToMinMax(x1, y1);
AddToMinMax(x2, y2);
}
else {
var theCanvas = document.getElementById("theCanvas");
var context = theCanvas.getContext("2d");
context.strokeStyle = "black";
if (IsStrong()) {
context.lineWidth = 2;
context.setLineDash([]);
}
else {//通常時
context.lineWidth = 1;
switch (dash) {
default:
context.setLineDash([]);
break;
case 1://山折 ─・・─・・
context.setLineDash([12, 2, 2, 2, 2, 2]);
break;
case 2://谷折り - - - -
context.setLineDash([6, 4]);
break;
}
}
context.beginPath();
context.moveTo(x1, y1);
context.lineTo(x2, y2);
context.stroke();
context.closePath();
context.setLineDash([]);
}
}
var g_LinePos = {x:0, y:0};
function GetLinePos()
{
return g_LinePos;
}
function MoveTo(x, y)
{
g_LinePos.x = x;
g_LinePos.y = y;
}
function MoveToDelta(dx, dy)
{
g_LinePos.x += dx;
g_LinePos.y += dy;
}
function LineTo(x, y, dash)
{
DrawLine(g_LinePos.x, g_LinePos.y, x, y, dash);
MoveTo(x, y);
}
function LineToDelta(dx, dy, dash)
{
var dst_x = g_LinePos.x + dx;
var dst_y = g_LinePos.y + dy;
DrawLine(g_LinePos.x, g_LinePos.y, dst_x, dst_y, dash);
MoveTo(dst_x, dst_y);
}
/// のりしろ描画用。引数は x1, y1, x2, y2, ...
function FillPolyWithPattern()
{
if (arguments.length % 2 != 0)
throw "FillPolyWithPattern args must be even";
if (g_DrawMode==0) {
for (var i=0; i<arguments.length; i+=2) {
AddToMinMax(arguments[i], arguments[i+1]);
}
}
else {
var ptncan = document.createElement("canvas");
ptncan.width = 32;
ptncan.height = 32;
var ptnctx = ptncan.getContext("2d");
ptnctx.strokeStyle = "#888888";
ptnctx.lineWidth = 1;
ptnctx.beginPath();
for (var i=0; i<ptncan.height; i+=2) {
//ピクセルの中間地点から描画するからぼやける?
//+0.5すればぼやけるのを防げる?
ptnctx.moveTo(0, i+.5);
ptnctx.lineTo(ptncan.width, i+.5);
}
// for (var i=-ptncan.width; i<ptncan.width; i+=2) {
// ptnctx.moveTo(i, 0);
// ptnctx.lineTo(i+ptncan.width, ptncan.height);
// }
ptnctx.stroke();
ptnctx.closePath();
var theCanvas = document.getElementById("theCanvas");
theCanvas.style.visibility = "visible";
var context = theCanvas.getContext("2d");
var pattern = context.createPattern(ptncan, "repeat");
context.fillStyle = pattern;
context.beginPath();
context.moveTo(arguments[0], arguments[1]);
for (var i=2; i<arguments.length; i+=2) {
context.lineTo(arguments[i], arguments[i+1]);
}
context.closePath();
context.fill();
context.fillStyle = "black";
}
}
//////////////////////////////////////////////////////////////////////////////
/// id要素のvalueをfloatで返す。無理ならthrow
function GetFloat(id)
{
var str = document.getElementById(id).value;
var ret = parseFloat(str);
if (Number.isNaN(ret)) {
var text = document.getElementById(id).name;
throw text+" に数値が入力されていません。";
}
return ret;
}
function GetPleatsType()
{
if (document.getElementById("KnifePleatsRadio").checked)
return KnifePleats;
if (document.getElementById("FrontBoxPleatsRadio").checked)
return FrontBoxPleats;
if (document.getElementById("InvertedPleatsRadio").checked)
return InvertedPleats;
}
/// パラメータを取得し、従属する値を計算
function GetParams()
{
var ret = {};
ret.Type = GetPleatsType();
ret.L1 = GetFloat("waistCirc");
ret.L2 = GetFloat("bottomCirc");
ret.H = GetFloat("skirtHeight");
ret.N = GetFloat("numPleats");
ret.Alpha = GetFloat("pleatsRatio");
ret.B = GetFloat("beltHeight");
ret.DrawInst = document.getElementById("drawInstruction").checked;
//入力をもとに、従属する値を求める
if (ret.Type==KnifePleats || ret.Type==FrontBoxPleats) {
//車ひだ・前箱ひだ用の値
ret.AB = ret.L1 / ( (1 - ret.Alpha) * ret.N );
ret.BC = ret.Alpha * ret.AB;
ret.DE = ret.L2 / ( (1 - ret.Alpha) * ret.N );
ret.EF = ret.Alpha * ret.DE;
ret.M1 = ret.N * (ret.AB + ret.BC);
ret.M2 = ret.N * (ret.DE + ret.EF);
ret.R = (ret.M1 * ret.H) / (ret.M2 - ret.M1);
ret.Theta = (ret.M2 - ret.M1) / ret.H;
}
else if (ret.Type==InvertedPleats) {
//ボックスプリーツ用
ret.DE = ret.L2 / ret.N;
ret.AB = ret.Alpha * ret.DE;
ret.BC = ret.AB * 2;
ret.EF = 0;
ret.M1 = ret.L1;
ret.M2 = (4 * ret.Alpha + 1 ) * ret.L2;
ret.R = (ret.M1 * ret.H) / (ret.M2 - ret.M1);
ret.Theta = (ret.M2 - ret.M1) / ret.H;
}
ret.toString = function() {
return "Type="+this.Type +", L1="+this.L1 +", L2="+this.L2 +", H="+this.H
+ ", N="+this.N +", α="+this.Alpha +", B="+this.B
+ ", AB="+this.AB +", BC="+this.BC +", DE="+this.DE +", EF="+this.EF
+ ", M1="+this.M1 +", M2="+this.M2 +", R="+this.R +", θ="+this.Theta;
};
return ret;
}
/// スカート部ののりしろを描画
function DrawTabForSticking(p, cx, cy)
{
var fillpts = [];//塗り用
var px, py, qx, qy;
px = cx;
py = cy-(p.R+p.H);
fillpts.push(px, py);
//のりしろの幅は最大でも min(AB, H/2) まで
var tab = Math.min(p.AB, p.H/2) * 0.8;
qx = px - tab;
qy = py + tab;
fillpts.push(qx, qy);
DrawLine( px, py, qx, qy );
px = qx;
py = qy;
qy = cy - p.R - tab;
fillpts.push(qx, qy);
DrawLine( px, py, qx, qy );
px = qx;
py = qy;
qx = cx;
qy = cy - p.R;
fillpts.push(qx, qy);
DrawLine( px, py, qx, qy );
//塗り
FillPolyWithPattern(...fillpts);
}
/// ベルト部を描画 (長さL1, 幅Bの長方形)
// 強度のために高さB*2にして折る。
function DrawBelt(p, x, y)
{
//アジャスターを模した長めの部分
var extend = p.B * 2;
// スカート部と接着するためののりしろもつける。
var tab = p.B;
var fillpts = [];
var px, py, qx, qy;
MoveTo(x, y);
LineToDelta(p.L1+extend, 0);
LineToDelta(0, p.B*2);
LineToDelta(-extend, 0);
MoveToDelta(-p.L1, 0);
LineToDelta(0, -p.B*2);
//ベルトの左下端と、アジャスタ部右上端を、接着
fillpts = [x+p.L1, y];
fillpts.push( x+p.L1+extend, y );
fillpts.push( x+p.L1+extend, y+p.B );
fillpts.push( x+p.L1, y+p.B );
FillPolyWithPattern(...fillpts);
// スカート部と接続するのりしろ
px = x;
py = y + p.B*2;
fillpts = [px, py];
for (var i=0; i<4; i++) {
qx = px + tab;
qy = py + tab;
DrawLine(px, py, qx, qy);
fillpts.push(qx, qy);
px = qx;
py = qy;
qx = px + p.L1 / 4 - tab*2;
DrawLine(px, py, qx, qy);
fillpts.push(qx, qy);
px = qx;
py = qy;
qx = px + tab;
qy = py - tab;
DrawLine(px, py, qx, qy);
fillpts.push(qx, qy);
FillPolyWithPattern(...fillpts);
px = qx;
py = qy;
}
//半分に折る線
DrawLine(x, y+p.B, x+p.L1+extend, y+p.B, 1);
return y + p.B*2 + tab;
}
/// 説明
function DrawInstruction(x, y)
{
DrawLine(x, y, x+200, y, 1);
DrawText("山折り", x+200, y-8);
y += 24;
DrawLine(x, y, x+200, y, 2);
DrawText("谷折り", x+200, y-8);
y += 16;
FillPolyWithPattern(x, y, x+200, y, x+200, y+16, x, y+16);
DrawText("のりしろ", x+200, y);
}
/// 車ひだ・前箱ひだ
function GenerateMain1(p)
{
//円の中心位置を求める
var cx = 0;
var cy = p.H + p.R;
//AB, BC に対する角度
var d_theta_ab = p.Theta / (p.N * (1 + p.Alpha) );
var d_theta_bc = p.Alpha * d_theta_ab;
//用紙節約のため、スカート部を2つの部品で構成する。
//それぞれの部品のプリーツ数
var n1 = Math.floor( p.N / 2 );
var n2 = p.N - n1;
//のりしろ+余白のぶん、円の中心を右下にずらす
var margin = p.AB * 2;
cx += margin;
cy += margin;
//前箱ヒダなら、途中で山折り・谷折りを逆転する。そのときのindexがこれ。
//前箱ヒダでなければ-1にして、indexに決して一致しないようにする。
var rev_indices = [];
if (p.Type==FrontBoxPleats) {
//のりしろを避けるために少し進んだインデクスで逆転する
rev_indices.push(Math.floor(n1/2));
rev_indices.push(p.N - rev_indices[0]);
}
else {
//車ひだの場合、逆転しない。
rev_indices = [-1];
}
//スカート部の描画
var max_y = 0;//ベルト部の印刷位置を決めるため
var index = 0;
var fold_two = 2, fold_one = 1;
for (var part=0; part<2; part++) {
DrawTabForSticking(p, cx, cy);
var divnum = (part==0 ? n1 : n2);
var part_theta = p.Theta * divnum / p.N;
DrawArc( cx, cy, p.R, -Math.PI/2, -Math.PI/2 + part_theta );
DrawArc( cx, cy, p.R + p.H, -Math.PI/2, -Math.PI/2 + part_theta );
for (var i=0; i<=divnum; i++) {
if (rev_indices.indexOf(index) != -1) {
[fold_one, fold_two] = [fold_two, fold_one];
}
var angle = -Math.PI/2 + (part_theta / divnum) * i;
var x1 = cx + Math.cos(angle) * p.R;
var y1 = cy + Math.sin(angle) * p.R;
var x2 = x1 + Math.cos(angle) * p.H;
var y2 = y1 + Math.sin(angle) * p.H;
DrawLine( x1, y1, x2, y2, (i==divnum) ? 0 : fold_two );
max_y = Math.max(max_y, y1);
max_y = Math.max(max_y, y2);
if (i < divnum) {
var angle2 = angle + d_theta_bc;
var x3 = cx + Math.cos(angle2) * p.R;
var y3 = cy + Math.sin(angle2) * p.R;
var x4 = x3 + Math.cos(angle2) * p.H;
var y4 = y3 + Math.sin(angle2) * p.H;
DrawLine( x3, y3, x4, y4, fold_one );
max_y = Math.max(max_y, y3);
max_y = Math.max(max_y, y4);
//腰まわりののりしろ
var x5 = x3 + Math.cos(angle2) * p.BC;
var y5 = y3 + Math.sin(angle2) * p.BC;
var x6 = x1 + Math.cos(angle) * p.BC;
var y6 = y1 + Math.sin(angle) * p.BC;
FillPolyWithPattern(x3, y3, x5, y5, x6, y6, x1, y1);
index++;
}
}
// 部品の高さ+余白だけ、下にずらす
cy += p.H + p.R * (1 - Math.cos(part_theta)) + p.BC;
}
// ベルト部を描画
var belt_y = max_y + p.BC * 2;
var inst_y = (p.B>0 ? DrawBelt(p, cx, belt_y) : belt_y ) + p.BC * 4;
if (p.DrawInst && !IsStrong()) DrawInstruction(margin, inst_y);
}
///ボックス
function GenerateMainInv(p)
{
//円の中心位置を求める
var ox = 0;
var oy = p.H + p.R;
//DE, AB に対する角度
var d_theta_de = p.Theta / (p.N * (1 + 4 * p.Alpha) );
var d_theta_ab = p.Alpha * d_theta_de;
//用紙節約のため、スカート部を2つの部品で構成する。
//それぞれの部品のプリーツ数
var n1 = Math.floor( p.N / 2 );
var n2 = p.N - n1;
//のりしろ+余白のぶん、円の中心を右下にずらす
var margin = p.AB * 2;
ox += margin;
oy += margin;
//スカート部の描画
var max_y = 0;//ベルト部の印刷位置を決めるため
for (var part=0; part<2; part++) {
DrawTabForSticking(p, ox, oy);
var divnum = (part==0 ? n1 : n2);
var part_theta = p.Theta * divnum / p.N;
//別パーツののりしろを隠すように、ウエスト側だけ広げる
DrawArc( ox, oy, p.R, -Math.PI/2, -Math.PI/2 + part_theta + d_theta_ab*2 );
DrawArc( ox, oy, p.R + p.H, -Math.PI/2, -Math.PI/2 + part_theta );
var before_max_y = max_y;
for (var i=0; i<=divnum; i++) {
var angle = -Math.PI/2 + (part_theta / divnum) * i;
if (i < divnum) {
// K
var kx = ox + Math.cos(angle + d_theta_ab*2) * p.R;
var ky = oy + Math.sin(angle + d_theta_ab*2) * p.R;
max_y = Math.max(max_y, ky);
//最初だけ、のりしろ拡張部
if (i==0) {
FillPolyWithPattern(ox, oy-p.R, ox, oy-p.R-p.H, kx, ky);
}
// A
var ax = ox + Math.cos(angle) * (p.R + p.H);
var ay = oy + Math.sin(angle) * (p.R + p.H);
DrawLine( kx, ky, ax, ay, 1 );
max_y = Math.max(max_y, ay);
// B
var bx = ox + Math.cos(angle + d_theta_ab) * (p.R + p.H);
var by = oy + Math.sin(angle + d_theta_ab) * (p.R + p.H);
DrawLine( kx, ky, bx, by, 2 );
max_y = Math.max(max_y, by);
// C
var cx = ox + Math.cos(angle + d_theta_ab*3) * (p.R + p.H);
var cy = oy + Math.sin(angle + d_theta_ab*3) * (p.R + p.H);
DrawLine( kx, ky, cx, cy, 2 );
max_y = Math.max(max_y, cy);
// D
var dx = ox + Math.cos(angle + d_theta_ab*4) * (p.R + p.H);
var dy = oy + Math.sin(angle + d_theta_ab*4) * (p.R + p.H);
DrawLine( kx, ky, dx, dy, 1 );
max_y = Math.max(max_y, dy);
}
else { //i==divnum: 最後
// K: 別パーツののりしろを隠すように、ウエスト側だけ広げる
var kx = ox + Math.cos(angle + d_theta_ab*2) * p.R;
var ky = oy + Math.sin(angle + d_theta_ab*2) * p.R;
max_y = Math.max(max_y, ky);
var ax = ox + Math.cos(angle) * (p.R + p.H);
var ay = oy + Math.sin(angle) * (p.R + p.H);
DrawLine( kx, ky, ax, ay, 0 );
max_y = Math.max(max_y, ay);
}
}
// 部品の高さだけ、下にずらす
oy += (max_y - before_max_y);
}
// ベルト部を描画
var belt_y = max_y + p.AB * 2;
var inst_y = (p.B>0 ? DrawBelt(p, ox, belt_y) : belt_y ) + p.AB * 4;
if (p.DrawInst && !IsStrong()) DrawInstruction(margin, inst_y);
}
function GenerateMain(p)
{
switch (p.Type)
{
default:
case KnifePleats: case FrontBoxPleats:
GenerateMain1(p);
break;
case InvertedPleats:
GenerateMainInv(p);
break;
}
}
function OnGenerateButton()
{
PrintDebug("Generate");
try {
var p = GetParams();
PrintDebug(p.toString());
ClearCanvas(500, 200);
ClearMinMax();
g_DrawMode = 0;
GenerateMain(p);
//描画範囲が確定したのでCanvasサイズを設定する
//余白を追加
g_MaxX += p.AB*2;
g_MaxY += p.AB;
g_DrawMode = 1;
ClearCanvas(g_MaxX, g_MaxY);
GenerateMain(p);
ConvertCanvasToImage();
}
catch (e) {
alert(e);
}
}
function OnResetButton()
{
if (confirm("パラメータを初期値に戻しますか?")) {
document.getElementById("theForm").reset();
}
}
</script>
</body></html>