codex-copilot-dx 1.4.15 → 1.4.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -468,369 +468,376 @@
468
468
  press(r, ...axis, phase, top + 8.3, 67);
469
469
  }
470
470
 
471
- const pressureAngle = Math.PI / 9;
472
- const involute = angle => Math.tan(angle) - angle;
473
- function makeWheel(teeth, windows, bore, moduleSize) {
474
- const pitchRadius = moduleSize * teeth / 2;
475
- const outerRadius = pitchRadius + moduleSize;
476
- const rootRadius = pitchRadius - 1.25 * moduleSize;
477
- const base = pitchRadius * Math.cos(pressureAngle);
478
- const rootFlank = Math.max(base, rootRadius);
479
- const step = tau / teeth;
480
- const halfTooth = step * 0.245;
481
- const halfAngle = (radius) => halfTooth + involute(pressureAngle) - involute(Math.acos(base / radius));
482
- const path = new Path2D();
483
- function point(radius, angle, move = false) {
484
- const x = radius * Math.cos(angle), y = radius * Math.sin(angle);
485
- const method = move ? "moveTo" : "lineTo";
486
- path[method](x, y);
487
- }
488
- for (let i = 0; i < teeth; i++) {
489
- const angle = i * step;
490
- point(rootRadius, angle - step / 2, i === 0);
491
- point(rootRadius, angle - halfAngle(rootFlank) - step * 0.055);
492
- for (let j = 0; j <= 4; j++) {
493
- const radius = rootFlank + (outerRadius - rootFlank) * j / 4;
494
- point(radius, angle - halfAngle(radius));
471
+ function buildClock() {
472
+ const pressureAngle = Math.PI / 9;
473
+ const involute = angle => Math.tan(angle) - angle;
474
+ function makeWheel(teeth, windows, bore, moduleSize) {
475
+ const pitchRadius = moduleSize * teeth / 2;
476
+ const outerRadius = pitchRadius + moduleSize;
477
+ const rootRadius = pitchRadius - 1.25 * moduleSize;
478
+ const base = pitchRadius * Math.cos(pressureAngle);
479
+ const rootFlank = Math.max(base, rootRadius);
480
+ const step = tau / teeth;
481
+ const halfTooth = step * 0.245;
482
+ const halfAngle = (radius) => halfTooth + involute(pressureAngle) - involute(Math.acos(base / radius));
483
+ const path = new Path2D();
484
+ function point(radius, angle, move = false) {
485
+ const x = radius * Math.cos(angle), y = radius * Math.sin(angle);
486
+ const method = move ? "moveTo" : "lineTo";
487
+ path[method](x, y);
495
488
  }
496
- for (let j = 4; j >= 0; j--) {
497
- const radius = rootFlank + (outerRadius - rootFlank) * j / 4;
498
- point(radius, angle + halfAngle(radius));
489
+ for (let i = 0; i < teeth; i++) {
490
+ const angle = i * step;
491
+ point(rootRadius, angle - step / 2, i === 0);
492
+ point(rootRadius, angle - halfAngle(rootFlank) - step * 0.055);
493
+ for (let j = 0; j <= 4; j++) {
494
+ const radius = rootFlank + (outerRadius - rootFlank) * j / 4;
495
+ point(radius, angle - halfAngle(radius));
496
+ }
497
+ for (let j = 4; j >= 0; j--) {
498
+ const radius = rootFlank + (outerRadius - rootFlank) * j / 4;
499
+ point(radius, angle + halfAngle(radius));
500
+ }
501
+ point(rootRadius, angle + halfAngle(rootFlank) + step * 0.055);
502
+ point(rootRadius, angle + step / 2);
499
503
  }
500
- point(rootRadius, angle + halfAngle(rootFlank) + step * 0.055);
501
- point(rootRadius, angle + step / 2);
502
- }
503
- path.closePath();
504
- const outerWindow = rootRadius - 3.2;
505
- const innerWindow = bore + 2.8;
506
- for (let i = 0; i < windows; i++) {
507
- const middle = i * tau / windows;
508
- const half = Math.PI / windows - 0.15;
509
- const from = middle - half, to = middle + half;
510
- path.moveTo(outerWindow * Math.cos(from), outerWindow * Math.sin(from));
511
- path.arc(0, 0, outerWindow, from, to);
512
- path.lineTo(innerWindow * Math.cos(to - 0.17), innerWindow * Math.sin(to - 0.17));
513
- path.arc(0, 0, innerWindow, to - 0.17, from + 0.17, true);
514
504
  path.closePath();
505
+ const outerWindow = rootRadius - 3.2;
506
+ const innerWindow = bore + 2.8;
507
+ for (let i = 0; i < windows; i++) {
508
+ const middle = i * tau / windows;
509
+ const half = Math.PI / windows - 0.15;
510
+ const from = middle - half, to = middle + half;
511
+ path.moveTo(outerWindow * Math.cos(from), outerWindow * Math.sin(from));
512
+ path.arc(0, 0, outerWindow, from, to);
513
+ path.lineTo(innerWindow * Math.cos(to - 0.17), innerWindow * Math.sin(to - 0.17));
514
+ path.arc(0, 0, innerWindow, to - 0.17, from + 0.17, true);
515
+ path.closePath();
516
+ }
517
+ return { teeth, pitchRadius, rootRadius, path, bore };
518
+ }
519
+
520
+ function polar(radius, angle) {
521
+ return [radius * Math.cos(angle), radius * Math.sin(angle)];
522
+ }
523
+
524
+ function offset([x, y], radius, angle) {
525
+ const [dx, dy] = polar(radius, angle);
526
+ return [x + dx, y + dy];
527
+ }
528
+
529
+ const minuteAxis = [-54, -27];
530
+ const minuteWheel = makeWheel(72, 6, 5.5, 0.75);
531
+ const minutePinion = makeWheel(12, 0, 3.2, 1);
532
+ const barrelWheel = makeWheel(58, 0, 4, 1);
533
+ const barrelOpening = 24;
534
+ barrelWheel.path.moveTo(barrelOpening, 0);
535
+ barrelWheel.path.arc(0, 0, barrelOpening, 0, tau);
536
+ barrelWheel.path.closePath();
537
+ const barrelMesh = -1.46;
538
+ const barrelAxis = offset(minuteAxis, barrelWheel.pitchRadius + minutePinion.pitchRadius, barrelMesh + Math.PI);
539
+
540
+ const thirdPinion = makeWheel(12, 0, 2.5, 0.75);
541
+ const thirdWheel = makeWheel(80, 5, 4.1, 0.67);
542
+ const thirdMesh = 0.12;
543
+ const thirdAxis = offset(minuteAxis, minuteWheel.pitchRadius + thirdPinion.pitchRadius, thirdMesh);
544
+
545
+ const secondsPinion = makeWheel(8, 0, 1.7, 0.67);
546
+ const secondsWheel = makeWheel(60, 5, 3.5, 0.60);
547
+ const secondsMesh = 0.45;
548
+ const secondsAxis = offset(thirdAxis, thirdWheel.pitchRadius + secondsPinion.pitchRadius, secondsMesh);
549
+
550
+ const escapePinion = makeWheel(10, 0, 1.8, 0.60);
551
+ const escapeMesh = -0.57;
552
+ const escapeAxis = offset(secondsAxis, secondsWheel.pitchRadius + escapePinion.pitchRadius, escapeMesh);
553
+ const leverAxis = -0.38;
554
+ const palletSpan = 22.5;
555
+ const balanceSpan = 46.5;
556
+ const balanceCenter = offset(escapeAxis, balanceSpan, leverAxis);
557
+ const palletCenter = offset(escapeAxis, palletSpan, leverAxis);
558
+ const escapeTeeth = 15;
559
+ const toothPitch = tau / escapeTeeth;
560
+ const toothTip = 15.2;
561
+ const lockAngle = 3.5 * toothPitch / 2;
562
+ const banking = 0.116;
563
+
564
+ const escapeWheel = new Path2D();
565
+ const clubTooth = [[10.7, -0.49], [10.7, -0.30], [13.65, 0.025], [toothTip, 0],
566
+ [15.05, 0.16], [13.85, 0.24], [10.7, 0.32]];
567
+ for (let i = 0; i < escapeTeeth; i++) {
568
+ for (const [j, [radius, fraction]] of clubTooth.entries()) {
569
+ const point = polar(radius, (i + fraction) * toothPitch);
570
+ if (i === 0 && j === 0) escapeWheel.moveTo(...point);
571
+ else escapeWheel.lineTo(...point);
572
+ }
515
573
  }
516
- return { teeth, pitchRadius, rootRadius, path, bore };
517
- }
518
-
519
- function polar(radius, angle) {
520
- return [radius * Math.cos(angle), radius * Math.sin(angle)];
521
- }
522
-
523
- function offset([x, y], radius, angle) {
524
- const [dx, dy] = polar(radius, angle);
525
- return [x + dx, y + dy];
526
- }
527
-
528
- const minuteAxis = [-54, -27];
529
- const minuteWheel = makeWheel(72, 6, 5.5, 0.75);
530
- const minutePinion = makeWheel(12, 0, 3.2, 1);
531
- const barrelWheel = makeWheel(58, 0, 4, 1);
532
- const barrelOpening = 24;
533
- barrelWheel.path.moveTo(barrelOpening, 0);
534
- barrelWheel.path.arc(0, 0, barrelOpening, 0, tau);
535
- barrelWheel.path.closePath();
536
- const barrelMesh = -1.46;
537
- const barrelAxis = offset(minuteAxis, barrelWheel.pitchRadius + minutePinion.pitchRadius, barrelMesh + Math.PI);
538
-
539
- const thirdPinion = makeWheel(12, 0, 2.5, 0.75);
540
- const thirdWheel = makeWheel(80, 5, 4.1, 0.67);
541
- const thirdMesh = 0.12;
542
- const thirdAxis = offset(minuteAxis, minuteWheel.pitchRadius + thirdPinion.pitchRadius, thirdMesh);
543
-
544
- const secondsPinion = makeWheel(8, 0, 1.7, 0.67);
545
- const secondsWheel = makeWheel(60, 5, 3.5, 0.60);
546
- const secondsMesh = 0.45;
547
- const secondsAxis = offset(thirdAxis, thirdWheel.pitchRadius + secondsPinion.pitchRadius, secondsMesh);
548
-
549
- const escapePinion = makeWheel(10, 0, 1.8, 0.60);
550
- const escapeMesh = -0.57;
551
- const escapeAxis = offset(secondsAxis, secondsWheel.pitchRadius + escapePinion.pitchRadius, escapeMesh);
552
- const leverAxis = -0.38;
553
- const palletSpan = 22.5;
554
- const balanceSpan = 46.5;
555
- const balanceCenter = offset(escapeAxis, balanceSpan, leverAxis);
556
- const palletCenter = offset(escapeAxis, palletSpan, leverAxis);
557
- const escapeTeeth = 15;
558
- const toothPitch = tau / escapeTeeth;
559
- const toothTip = 15.2;
560
- const lockAngle = 3.5 * toothPitch / 2;
561
- const banking = 0.116;
562
-
563
- const escapeWheel = new Path2D();
564
- const clubTooth = [[10.7, -0.49], [10.7, -0.30], [13.65, 0.025], [toothTip, 0],
565
- [15.05, 0.16], [13.85, 0.24], [10.7, 0.32]];
566
- for (let i = 0; i < escapeTeeth; i++) {
567
- for (const [j, [radius, fraction]] of clubTooth.entries()) {
568
- const point = polar(radius, (i + fraction) * toothPitch);
569
- if (i === 0 && j === 0) escapeWheel.moveTo(...point);
570
- else escapeWheel.lineTo(...point);
571
- }
572
- }
573
- escapeWheel.closePath();
574
- for (let i = 0; i < 5; i++) {
575
- const start = i * tau / 5 + 0.13, end = start + tau / 5 - 0.26;
576
- escapeWheel.moveTo(...polar(8.95, start));
577
- escapeWheel.arc(0, 0, 8.95, start, end);
578
- escapeWheel.lineTo(...polar(3.6, end - 0.17));
579
- escapeWheel.arc(0, 0, 3.6, end - 0.17, start + 0.17, true);
580
574
  escapeWheel.closePath();
581
- }
582
-
583
- // External mesh phases, solved backwards from the intermittent escape-wheel motion.
584
- function drivingAngle(wheel, pinion, driven, axis) {
585
- const alignment = (wheel.teeth + pinion.teeth) * axis + pinion.teeth * Math.PI - Math.PI;
586
- return (alignment - driven * pinion.teeth) / wheel.teeth;
587
- }
588
-
589
- function clockPose(distance) {
590
- const time = distance * 5.6;
591
- const beat = Math.floor(time);
592
- const phase = time - beat;
593
- const direction = beat % 2 === 0 ? 1 : -1;
594
- const advance = (beat + segment(phase, 0.50, 0.70)) * toothPitch / 2;
595
- const escape = leverAxis + lockAngle - advance;
596
- const seconds = drivingAngle(secondsWheel, escapePinion, escape, escapeMesh);
597
- const third = drivingAngle(thirdWheel, secondsPinion, seconds, secondsMesh);
598
- const minute = drivingAngle(minuteWheel, thirdPinion, third, thirdMesh);
599
- const barrel = drivingAngle(barrelWheel, minutePinion, minute, barrelMesh);
600
- return {
601
- escape, seconds, third, minute, barrel,
602
- pallet: direction * banking * (1 - 2 * segment(phase, 0.42, 0.61)),
603
- balance: -1.78 * Math.cos(Math.PI * time)
604
- };
605
- }
575
+ for (let i = 0; i < 5; i++) {
576
+ const start = i * tau / 5 + 0.13, end = start + tau / 5 - 0.26;
577
+ escapeWheel.moveTo(...polar(8.95, start));
578
+ escapeWheel.arc(0, 0, 8.95, start, end);
579
+ escapeWheel.lineTo(...polar(3.6, end - 0.17));
580
+ escapeWheel.arc(0, 0, 3.6, end - 0.17, start + 0.17, true);
581
+ escapeWheel.closePath();
582
+ }
583
+
584
+ // External mesh phases, solved backwards from the intermittent escape-wheel motion.
585
+ function drivingAngle(wheel, pinion, driven, axis) {
586
+ const alignment = (wheel.teeth + pinion.teeth) * axis + pinion.teeth * Math.PI - Math.PI;
587
+ return (alignment - driven * pinion.teeth) / wheel.teeth;
588
+ }
589
+
590
+ function clockPose(distance) {
591
+ const time = distance * 5.6;
592
+ const beat = Math.floor(time);
593
+ const phase = time - beat;
594
+ const direction = beat % 2 === 0 ? 1 : -1;
595
+ const advance = (beat + segment(phase, 0.50, 0.70)) * toothPitch / 2;
596
+ const escape = leverAxis + lockAngle - advance;
597
+ const seconds = drivingAngle(secondsWheel, escapePinion, escape, escapeMesh);
598
+ const third = drivingAngle(thirdWheel, secondsPinion, seconds, secondsMesh);
599
+ const minute = drivingAngle(minuteWheel, thirdPinion, third, thirdMesh);
600
+ const barrel = drivingAngle(barrelWheel, minutePinion, minute, barrelMesh);
601
+ return {
602
+ escape, seconds, third, minute, barrel,
603
+ pallet: direction * banking * (1 - 2 * segment(phase, 0.42, 0.61)),
604
+ balance: -1.78 * Math.cos(Math.PI * time)
605
+ };
606
+ }
606
607
 
607
- const initialClock = clockPose(0);
608
+ const initialClock = clockPose(0);
608
609
 
609
- function gearFace(r, axis, height, gear, angle, finish = "paper") {
610
- const { path, bore, rootRadius } = gear;
611
- for (const z of [height - 1.8, height - 0.9]) {
612
- r.plane(...axis, z, angle, () => r.outline(path, "flank", null));
610
+ function gearFace(r, axis, height, gear, angle, finish = "paper") {
611
+ const { path, bore, rootRadius } = gear;
612
+ for (const z of [height - 1.8, height - 0.9]) {
613
+ r.plane(...axis, z, angle, () => r.outline(path, "flank", null));
614
+ }
615
+ r.plane(...axis, height, angle, () => r.outline(path, finish));
616
+ if (rootRadius - bore > 6) r.circle(...axis, height + 0.02, rootRadius - 1.27, null, "soft", 0.38);
617
+ r.flange(...axis, height, bore, 1.25, 0, "side");
618
+ r.circle(...axis, height + 1.27, bore * 0.5, "recess", "line", 0.44);
619
+ r.line([...offset(axis, -bore * 0.39, angle), height + 1.31],
620
+ [...offset(axis, bore * 0.39, angle), height + 1.31], "ink", 0.48);
613
621
  }
614
- r.plane(...axis, height, angle, () => r.outline(path, finish));
615
- if (rootRadius - bore > 6) r.circle(...axis, height + 0.02, rootRadius - 1.27, null, "soft", 0.38);
616
- r.flange(...axis, height, bore, 1.25, 0, "side");
617
- r.circle(...axis, height + 1.27, bore * 0.5, "recess", "line", 0.44);
618
- r.line([...offset(axis, -bore * 0.39, angle), height + 1.31],
619
- [...offset(axis, bore * 0.39, angle), height + 1.31], "ink", 0.48);
620
- }
621
622
 
622
- function drawCoil(r, center, height, inner, outer, turns, wind, weight) {
623
- const path = new Path2D();
624
- const count = Math.ceil(turns * 29);
625
- for (let i = 0; i <= count; i++) {
626
- const fraction = i / count;
627
- const point = polar(mix(inner, outer, fraction), tau * turns * fraction + wind * (1 - fraction));
628
- if (i === 0) path.moveTo(...point);
629
- else path.lineTo(...point);
623
+ function drawCoil(r, center, height, inner, outer, turns, wind, weight) {
624
+ const path = new Path2D();
625
+ const count = Math.ceil(turns * 29);
626
+ for (let i = 0; i <= count; i++) {
627
+ const fraction = i / count;
628
+ const point = polar(mix(inner, outer, fraction), tau * turns * fraction + wind * (1 - fraction));
629
+ if (i === 0) path.moveTo(...point);
630
+ else path.lineTo(...point);
631
+ }
632
+ r.plane(...center, height, 0, () => r.outline(path, null, "line", weight));
630
633
  }
631
- r.plane(...center, height, 0, () => r.outline(path, null, "line", weight));
632
- }
633
-
634
- function clockBridge(r, from, bearing, height, width, pillar = 2.9) {
635
- r.flange(...from, 5, pillar, height - 9.65, 0, "metal");
636
- armLink(r, from, bearing, height, width);
637
- r.hole(...from, height + 0.04, width - 0.75);
638
- r.flange(...bearing, height - 0.8, width + 0.95, 1.35, 0, "metal");
639
- r.circle(...bearing, height + 0.57, width * 0.54, "recess", "ink", 0.55);
640
- r.circle(...bearing, height + 0.60, width * 0.25, "paper", "soft", 0.46);
641
- }
642
634
 
643
- function dialHand(r, axis, length, width, height, angle, fill) {
644
- r.plane(...axis, height, angle - Math.PI / 2, () => {
645
- const path = new Path2D();
646
- path.moveTo(-3.4, -width * 0.65);
647
- path.lineTo(length - 3.2, -width);
648
- path.lineTo(length, 0);
649
- path.lineTo(length - 3.2, width);
650
- path.lineTo(-3.4, width * 0.65);
651
- path.closePath();
652
- r.outline(path, fill, "ink", 0.46);
653
- });
654
- }
635
+ function clockBridge(r, from, bearing, height, width, pillar = 2.9) {
636
+ r.flange(...from, 5, pillar, height - 9.65, 0, "metal");
637
+ armLink(r, from, bearing, height, width);
638
+ r.hole(...from, height + 0.04, width - 0.75);
639
+ r.flange(...bearing, height - 0.8, width + 0.95, 1.35, 0, "metal");
640
+ r.circle(...bearing, height + 0.57, width * 0.54, "recess", "ink", 0.55);
641
+ r.circle(...bearing, height + 0.60, width * 0.25, "paper", "soft", 0.46);
642
+ }
655
643
 
656
- function drawDial(r, rotations) {
657
- const top = 33;
658
- const radius = 25.6;
659
- r.flange(...minuteAxis, 19.65, 1.57, top - 19.65, 0, "metal");
660
- for (const angle of [-2.6, -1.35, 2.55]) {
661
- const stud = offset(minuteAxis, 31.2, angle);
662
- r.flange(...stud, 5, 2.9, top - 9.8, 0, "side");
663
- armLink(r, stud, offset(minuteAxis, radius - 3, angle), top - 1.8, 2.1);
664
- r.hole(...stud, top - 1.75, 1.29);
665
- }
666
- r.flange(...minuteAxis, top - 2.1, radius, 2.1, 0, "paper");
667
- r.circle(...minuteAxis, top + 0.03, 23.9, null, "soft", 0.44);
668
- r.circle(...minuteAxis, top + 0.05, 17.6, null, "soft", 0.38);
669
- for (let i = 0; i < 60; i++) {
670
- const angle = i * tau / 60 - Math.PI / 2;
671
- const inner = i % 15 === 0 ? 18.7 : i % 5 === 0 ? 19.85 : 21.75;
672
- r.line([...offset(minuteAxis, inner, angle), top + 0.09],
673
- [...offset(minuteAxis, 22.85, angle), top + 0.09], i % 5 === 0 ? "ink" : "soft", i % 15 === 0 ? 1.24 : 0.49);
674
- }
675
- const traveled = rotations.minute - initialClock.minute;
676
- const initialTime = 10 * 3600 + 8 * 60;
677
- dialHand(r, minuteAxis, 13.9, 1.35, top + 0.57, initialTime * tau / 43200 + traveled / 12, "ink");
678
- dialHand(r, minuteAxis, 21.4, 1.0, top + 1.08, initialTime * tau / 3600 + traveled, "ink");
679
- r.flange(...minuteAxis, top + 1.1, 1.8, 1.25, 0, "side");
680
- }
644
+ function dialHand(r, axis, length, width, height, angle, fill) {
645
+ r.plane(...axis, height, angle - Math.PI / 2, () => {
646
+ const path = new Path2D();
647
+ path.moveTo(-3.4, -width * 0.65);
648
+ path.lineTo(length - 3.2, -width);
649
+ path.lineTo(length, 0);
650
+ path.lineTo(length - 3.2, width);
651
+ path.lineTo(-3.4, width * 0.65);
652
+ path.closePath();
653
+ r.outline(path, fill, "ink", 0.46);
654
+ });
655
+ }
681
656
 
682
- function drawSeconds(r, rotations) {
683
- const height = 29.5;
684
- const anchor = offset(secondsAxis, 14.3, 1.05);
685
- r.flange(...anchor, 5, 2.15, height - 6, 0, "side");
686
- const rim = new Path2D();
687
- rim.arc(0, 0, 10.2, 0, tau);
688
- rim.moveTo(8.1, 0);
689
- rim.arc(0, 0, 8.1, 0, tau);
690
- r.plane(...secondsAxis, height - 1.5, 0, () => r.outline(rim, "side"));
691
- r.plane(...secondsAxis, height, 0, () => r.outline(rim, "paper"));
692
- r.line([...offset(secondsAxis, 10.05, 1.05), height], [...anchor, height], "ink", 1.8);
693
- r.hole(...anchor, height + 0.03, 1.23);
694
- for (let i = 0; i < 12; i++) {
695
- const angle = i * tau / 12;
696
- r.line([...offset(secondsAxis, 8.5, angle), height + 0.04],
697
- [...offset(secondsAxis, 9.7, angle), height + 0.04], "ink", i % 3 === 0 ? 0.75 : 0.43);
698
- }
699
- r.flange(...secondsAxis, 27.2, 1.13, height - 25.7, 0, "metal");
700
- dialHand(r, secondsAxis, 8.4, 0.33, height + 0.92, rotations.seconds - initialClock.seconds + 0.35, "ink");
701
- r.circle(...secondsAxis, height + 1.02, 1.15, "recess", "line", 0.47);
702
- }
657
+ function drawDial(r, rotations) {
658
+ const top = 33;
659
+ const radius = 25.6;
660
+ r.flange(...minuteAxis, 19.65, 1.57, top - 19.65, 0, "metal");
661
+ for (const angle of [-2.6, -1.35, 2.55]) {
662
+ const stud = offset(minuteAxis, 31.2, angle);
663
+ r.flange(...stud, 5, 2.9, top - 9.8, 0, "side");
664
+ armLink(r, stud, offset(minuteAxis, radius - 3, angle), top - 1.8, 2.1);
665
+ r.hole(...stud, top - 1.75, 1.29);
666
+ }
667
+ r.flange(...minuteAxis, top - 2.1, radius, 2.1, 0, "paper");
668
+ r.circle(...minuteAxis, top + 0.03, 23.9, null, "soft", 0.44);
669
+ r.circle(...minuteAxis, top + 0.05, 17.6, null, "soft", 0.38);
670
+ for (let i = 0; i < 60; i++) {
671
+ const angle = i * tau / 60 - Math.PI / 2;
672
+ const inner = i % 15 === 0 ? 18.7 : i % 5 === 0 ? 19.85 : 21.75;
673
+ r.line([...offset(minuteAxis, inner, angle), top + 0.09],
674
+ [...offset(minuteAxis, 22.85, angle), top + 0.09], i % 5 === 0 ? "ink" : "soft", i % 15 === 0 ? 1.24 : 0.49);
675
+ }
676
+ const traveled = rotations.minute - initialClock.minute;
677
+ const initialTime = 10 * 3600 + 8 * 60;
678
+ dialHand(r, minuteAxis, 13.9, 1.35, top + 0.57, initialTime * tau / 43200 + traveled / 12, "ink");
679
+ dialHand(r, minuteAxis, 21.4, 1.0, top + 1.08, initialTime * tau / 3600 + traveled, "ink");
680
+ r.flange(...minuteAxis, top + 1.1, 1.8, 1.25, 0, "side");
681
+ }
682
+
683
+ function drawSeconds(r, rotations) {
684
+ const height = 29.5;
685
+ const anchor = offset(secondsAxis, 14.3, 1.05);
686
+ r.flange(...anchor, 5, 2.15, height - 6, 0, "side");
687
+ const rim = new Path2D();
688
+ rim.arc(0, 0, 10.2, 0, tau);
689
+ rim.moveTo(8.1, 0);
690
+ rim.arc(0, 0, 8.1, 0, tau);
691
+ r.plane(...secondsAxis, height - 1.5, 0, () => r.outline(rim, "side"));
692
+ r.plane(...secondsAxis, height, 0, () => r.outline(rim, "paper"));
693
+ r.line([...offset(secondsAxis, 10.05, 1.05), height], [...anchor, height], "ink", 1.8);
694
+ r.hole(...anchor, height + 0.03, 1.23);
695
+ for (let i = 0; i < 12; i++) {
696
+ const angle = i * tau / 12;
697
+ r.line([...offset(secondsAxis, 8.5, angle), height + 0.04],
698
+ [...offset(secondsAxis, 9.7, angle), height + 0.04], "ink", i % 3 === 0 ? 0.75 : 0.43);
699
+ }
700
+ r.flange(...secondsAxis, 27.2, 1.13, height - 25.7, 0, "metal");
701
+ dialHand(r, secondsAxis, 8.4, 0.33, height + 0.92, rotations.seconds - initialClock.seconds + 0.35, "ink");
702
+ r.circle(...secondsAxis, height + 1.02, 1.15, "recess", "line", 0.47);
703
+ }
704
+
705
+ function palletStone(side) {
706
+ // Transform the contact face at the tooth tip back into the lever's coordinates.
707
+ const angle = side * lockAngle;
708
+ const [x, y] = polar(toothTip + 0.04, angle);
709
+ const [nx, ny] = polar(1, angle);
710
+ const [tx, ty] = [-ny, nx];
711
+ const reverse = -side * banking;
712
+ const c = Math.cos(reverse), s = Math.sin(reverse);
713
+ return [[0, -1.35], [0, 1.35], [1.9, 1.35], [2.25, -1.35]].map(([a, b]) => {
714
+ const dx = x + nx * a + tx * b - palletSpan, dy = y + ny * a + ty * b;
715
+ return [dx * c - dy * s, dx * s + dy * c];
716
+ });
717
+ }
703
718
 
704
- function palletStone(side) {
705
- // Transform the contact face at the tooth tip back into the lever's coordinates.
706
- const angle = side * lockAngle;
707
- const [x, y] = polar(toothTip + 0.04, angle);
708
- const [nx, ny] = polar(1, angle);
709
- const [tx, ty] = [-ny, nx];
710
- const reverse = -side * banking;
711
- const c = Math.cos(reverse), s = Math.sin(reverse);
712
- return [[0, -1.35], [0, 1.35], [1.9, 1.35], [2.25, -1.35]].map(([a, b]) => {
713
- const dx = x + nx * a + tx * b - palletSpan, dy = y + ny * a + ty * b;
714
- return [dx * c - dy * s, dx * s + dy * c];
715
- });
716
- }
719
+ const palletStones = [-1, 1].map(palletStone);
717
720
 
718
- const palletStones = [-1, 1].map(palletStone);
721
+ function drawPallet(r, angle) {
722
+ const z = 22.7;
723
+ for (const side of [-1, 1]) {
724
+ const bank = offset(palletCenter, 12.7, leverAxis + side * 0.27);
725
+ r.flange(...bank, 5, 1.18, z - 4.2, 0, "metal");
726
+ }
727
+ r.flange(...palletCenter, 5, 1.63, z - 5, 0, "side");
728
+ const outline = (points, fill, stroke = "line", weight = 0.57) => {
729
+ const a = leverAxis + angle;
730
+ const c = Math.cos(a), s = Math.sin(a);
731
+ r.shape(points.map(([x, y]) => [palletCenter[0] + x * c - y * s,
732
+ palletCenter[1] + x * s + y * c, z]), fill, stroke, weight);
733
+ };
734
+ for (const stone of palletStones) {
735
+ const back = [(stone[2][0] + stone[3][0]) / 2, (stone[2][1] + stone[3][1]) / 2];
736
+ outline([[-1.8, -1.18], [back[0] - 0.5, back[1] - 1.04],
737
+ [back[0] + 0.96, back[1] + 0.9], [-1.1, 1.25]], "metal");
738
+ outline(stone, "recess", "ink", 0.5);
739
+ }
740
+ outline([[-2.7, -1.7], [10.3, -1.35], [16.1, -2.64], [19, -2.5], [17.15, -0.77],
741
+ [15.7, -0.58], [15.7, 0.58], [17.15, 0.77], [19, 2.5], [16.1, 2.64],
742
+ [10.3, 1.35], [-2.7, 1.7]], "paper");
743
+ r.flange(...palletCenter, z, 2.1, 1.0, 0, "side");
744
+ r.circle(...palletCenter, z + 1.05, 0.77, "recess", "ink", 0.45);
745
+ }
746
+
747
+ const balanceRadius = 20.8;
748
+ const balanceRim = new Path2D();
749
+ for (const radius of [balanceRadius, balanceRadius - 2.85]) {
750
+ balanceRim.moveTo(radius, 0);
751
+ balanceRim.arc(0, 0, radius, 0, tau);
752
+ balanceRim.closePath();
753
+ }
754
+
755
+ function drawBalance(r, angle, palletAngle) {
756
+ const height = 33.3;
757
+ r.flange(...balanceCenter, 5, 2.7, height - 6, 0, "side");
758
+ r.flange(...balanceCenter, 20.4, 7.65, 1.05, 0, "flank");
759
+ drawPallet(r, palletAngle);
760
+ const impulse = offset(balanceCenter, 6.65, leverAxis + Math.PI + angle);
761
+ r.flange(...impulse, 21.45, 0.83, 1.63, 0, "recess");
762
+ for (const z of [height - 2.5, height - 1.25]) {
763
+ r.plane(...balanceCenter, z, angle, () => r.outline(balanceRim, "flank", null));
764
+ }
765
+ for (let i = 0; i < 3; i++) {
766
+ const tip = offset(balanceCenter, balanceRadius - 1.7, angle + i * tau / 3 + 0.3);
767
+ armLink(r, balanceCenter, tip, height - 0.08, 1.32);
768
+ }
769
+ r.plane(...balanceCenter, height, angle, () => r.outline(balanceRim, "paper"));
770
+ r.circle(...balanceCenter, height + 0.025, balanceRadius - 0.87, null, "soft", 0.36);
771
+ for (let i = 0; i < 12; i++) {
772
+ const direction = angle + i * tau / 12;
773
+ const outer = offset(balanceCenter, balanceRadius - 1.43, direction);
774
+ r.circle(...outer, height + 0.04, 0.58, "recess", "ink", 0.33);
775
+ }
776
+ r.flange(...balanceCenter, height, 2.9, 1.1, 0, "metal");
777
+ drawCoil(r, balanceCenter, height + 2.15, 2.3, 11.9, 3.5, angle, 0.59);
778
+ const stud = offset(balanceCenter, 11.9, Math.PI);
779
+ r.flange(...stud, height + 1.5, 1.34, 1.44, 0, "side");
780
+ // Two narrow, stationary supports expose the spring and the regulating rim.
781
+ clockBridge(r, offset(balanceCenter, 23.8, -1.15), balanceCenter, height + 6.4, 2.0);
782
+ const studBase = offset(balanceCenter, 22.4, 2.04);
783
+ r.flange(...studBase, 5, 2.32, height - 4, 0, "metal");
784
+ armLink(r, studBase, stud, height + 2.98, 1.08);
785
+ r.hole(...studBase, height + 3.03, 0.91);
786
+ }
787
+
788
+ return function drawClock(r, distance) {
789
+ const pose = clockPose(distance);
790
+ r.layer("plate", r => {
791
+ const edge = [[-84, -65], [78, -65], [89, -54], [89, 2],
792
+ [64, 30], [27, 48], [-84, 48], [-95, 38], [-95, -54]];
793
+ const face = edge.map(([x, y]) => [x, y, 5]);
794
+ r.shape(edge.map(([x, y]) => [x + 3.1, y + 4.1, 0]), "shadow", null);
795
+ for (const i of [2, 3, 4, 5, 6]) {
796
+ const a = face[i], b = face[i + 1];
797
+ r.shape([a, b, [b[0], b[1], 0], [a[0], a[1], 0]], i === 5 ? "flank" : "side");
798
+ }
799
+ r.shape(face, "metal");
800
+ const rim = edge.map(([x, y]) => [x * 0.958, (y + 7) * 0.94 - 7, 5.04]);
801
+ r.shape([...rim, rim[0]], null, "soft", 0.48);
802
+ for (const [x, y] of [[-86, -55], [-86, 37], [79, -54], [60, 26]]) {
803
+ r.circle(x, y, 5.06, 2.62, "flank", "soft", 0.47);
804
+ r.hole(x, y, 5.1, 1.56);
805
+ }
806
+ for (const axis of [minuteAxis, thirdAxis, secondsAxis, escapeAxis]) r.flange(...axis, 5, 2.18, 2.28, 0, "side");
719
807
 
720
- function drawPallet(r, angle) {
721
- const z = 22.7;
722
- for (const side of [-1, 1]) {
723
- const bank = offset(palletCenter, 12.7, leverAxis + side * 0.27);
724
- r.flange(...bank, 5, 1.18, z - 4.2, 0, "metal");
725
- }
726
- r.flange(...palletCenter, 5, 1.63, z - 5, 0, "side");
727
- const outline = (points, fill, stroke = "line", weight = 0.57) => {
728
- const a = leverAxis + angle;
729
- const c = Math.cos(a), s = Math.sin(a);
730
- r.shape(points.map(([x, y]) => [palletCenter[0] + x * c - y * s,
731
- palletCenter[1] + x * s + y * c, z]), fill, stroke, weight);
808
+ });
809
+ r.flange(...barrelAxis, 5, 26.25, 3.4, 0, "side");
810
+ r.circle(...barrelAxis, 8.43, barrelOpening, "flank", "soft", 0.46);
811
+ drawCoil(r, barrelAxis, 8.50, 5.2, barrelOpening - 0.72, 5.5, pose.barrel, 0.66);
812
+ gearFace(r, barrelAxis, 10.7, barrelWheel, pose.barrel);
813
+ gearFace(r, minuteAxis, 10.7, minutePinion, pose.minute, "side");
814
+ r.flange(...minuteAxis, 11.94, 1.75, 4.25, 0, "metal");
815
+ r.flange(...secondsAxis, 7.25, 1.57, 3.45, 0, "metal");
816
+ gearFace(r, secondsAxis, 13.7, secondsWheel, pose.seconds);
817
+ r.flange(...escapeAxis, 7.26, 1.17, 3.55, 0, "metal");
818
+ gearFace(r, escapeAxis, 13.7, escapePinion, pose.escape, "side");
819
+
820
+ r.flange(...thirdAxis, 7.25, 1.6, 9.1, 0, "metal");
821
+ gearFace(r, minuteAxis, 18.4, minuteWheel, pose.minute);
822
+ gearFace(r, thirdAxis, 18.4, thirdPinion, pose.third, "side");
823
+ r.flange(...thirdAxis, 19.6, 1.83, 4.64, 0, "metal");
824
+ r.flange(...secondsAxis, 14.9, 1.55, 9.37, 0, "metal");
825
+ r.flange(...escapeAxis, 14.95, 1.32, 6.0, 0, "metal");
826
+ gearFace(r, escapeAxis, 22.7, { path: escapeWheel, bore: 2.2, rootRadius: 10.7 }, pose.escape);
827
+ gearFace(r, thirdAxis, 26.2, thirdWheel, pose.third);
828
+ gearFace(r, secondsAxis, 26.2, secondsPinion, pose.seconds, "side");
829
+
830
+ clockBridge(r, offset(barrelAxis, 28.2, 2.1), barrelAxis, 16.2, 2.35);
831
+ clockBridge(r, offset(thirdAxis, 26, -1.22), thirdAxis, 31.3, 2.14);
832
+ drawBalance(r, pose.balance, pose.pallet);
833
+ drawSeconds(r, pose);
834
+ drawDial(r, pose);
732
835
  };
733
- for (const stone of palletStones) {
734
- const back = [(stone[2][0] + stone[3][0]) / 2, (stone[2][1] + stone[3][1]) / 2];
735
- outline([[-1.8, -1.18], [back[0] - 0.5, back[1] - 1.04],
736
- [back[0] + 0.96, back[1] + 0.9], [-1.1, 1.25]], "metal");
737
- outline(stone, "recess", "ink", 0.5);
738
- }
739
- outline([[-2.7, -1.7], [10.3, -1.35], [16.1, -2.64], [19, -2.5], [17.15, -0.77],
740
- [15.7, -0.58], [15.7, 0.58], [17.15, 0.77], [19, 2.5], [16.1, 2.64],
741
- [10.3, 1.35], [-2.7, 1.7]], "paper");
742
- r.flange(...palletCenter, z, 2.1, 1.0, 0, "side");
743
- r.circle(...palletCenter, z + 1.05, 0.77, "recess", "ink", 0.45);
744
- }
745
-
746
- const balanceRadius = 20.8;
747
- const balanceRim = new Path2D();
748
- for (const radius of [balanceRadius, balanceRadius - 2.85]) {
749
- balanceRim.moveTo(radius, 0);
750
- balanceRim.arc(0, 0, radius, 0, tau);
751
- balanceRim.closePath();
752
- }
753
-
754
- function drawBalance(r, angle, palletAngle) {
755
- const height = 33.3;
756
- r.flange(...balanceCenter, 5, 2.7, height - 6, 0, "side");
757
- r.flange(...balanceCenter, 20.4, 7.65, 1.05, 0, "flank");
758
- drawPallet(r, palletAngle);
759
- const impulse = offset(balanceCenter, 6.65, leverAxis + Math.PI + angle);
760
- r.flange(...impulse, 21.45, 0.83, 1.63, 0, "recess");
761
- for (const z of [height - 2.5, height - 1.25]) {
762
- r.plane(...balanceCenter, z, angle, () => r.outline(balanceRim, "flank", null));
763
- }
764
- for (let i = 0; i < 3; i++) {
765
- const tip = offset(balanceCenter, balanceRadius - 1.7, angle + i * tau / 3 + 0.3);
766
- armLink(r, balanceCenter, tip, height - 0.08, 1.32);
767
- }
768
- r.plane(...balanceCenter, height, angle, () => r.outline(balanceRim, "paper"));
769
- r.circle(...balanceCenter, height + 0.025, balanceRadius - 0.87, null, "soft", 0.36);
770
- for (let i = 0; i < 12; i++) {
771
- const direction = angle + i * tau / 12;
772
- const outer = offset(balanceCenter, balanceRadius - 1.43, direction);
773
- r.circle(...outer, height + 0.04, 0.58, "recess", "ink", 0.33);
774
- }
775
- r.flange(...balanceCenter, height, 2.9, 1.1, 0, "metal");
776
- drawCoil(r, balanceCenter, height + 2.15, 2.3, 11.9, 3.5, angle, 0.59);
777
- const stud = offset(balanceCenter, 11.9, Math.PI);
778
- r.flange(...stud, height + 1.5, 1.34, 1.44, 0, "side");
779
- // Two narrow, stationary supports expose the spring and the regulating rim.
780
- clockBridge(r, offset(balanceCenter, 23.8, -1.15), balanceCenter, height + 6.4, 2.0);
781
- const studBase = offset(balanceCenter, 22.4, 2.04);
782
- r.flange(...studBase, 5, 2.32, height - 4, 0, "metal");
783
- armLink(r, studBase, stud, height + 2.98, 1.08);
784
- r.hole(...studBase, height + 3.03, 0.91);
785
836
  }
786
-
837
+ let clockRenderer;
787
838
  function displayClock(r, distance) {
788
- const pose = clockPose(distance);
789
- r.layer("plate", r => {
790
- const edge = [[-84, -65], [78, -65], [89, -54], [89, 2],
791
- [64, 30], [27, 48], [-84, 48], [-95, 38], [-95, -54]];
792
- const face = edge.map(([x, y]) => [x, y, 5]);
793
- r.shape(edge.map(([x, y]) => [x + 3.1, y + 4.1, 0]), "shadow", null);
794
- for (const i of [2, 3, 4, 5, 6]) {
795
- const a = face[i], b = face[i + 1];
796
- r.shape([a, b, [b[0], b[1], 0], [a[0], a[1], 0]], i === 5 ? "flank" : "side");
797
- }
798
- r.shape(face, "metal");
799
- const rim = edge.map(([x, y]) => [x * 0.958, (y + 7) * 0.94 - 7, 5.04]);
800
- r.shape([...rim, rim[0]], null, "soft", 0.48);
801
- for (const [x, y] of [[-86, -55], [-86, 37], [79, -54], [60, 26]]) {
802
- r.circle(x, y, 5.06, 2.62, "flank", "soft", 0.47);
803
- r.hole(x, y, 5.1, 1.56);
804
- }
805
- for (const axis of [minuteAxis, thirdAxis, secondsAxis, escapeAxis]) r.flange(...axis, 5, 2.18, 2.28, 0, "side");
806
-
807
- });
808
- r.flange(...barrelAxis, 5, 26.25, 3.4, 0, "side");
809
- r.circle(...barrelAxis, 8.43, barrelOpening, "flank", "soft", 0.46);
810
- drawCoil(r, barrelAxis, 8.50, 5.2, barrelOpening - 0.72, 5.5, pose.barrel, 0.66);
811
- gearFace(r, barrelAxis, 10.7, barrelWheel, pose.barrel);
812
- gearFace(r, minuteAxis, 10.7, minutePinion, pose.minute, "side");
813
- r.flange(...minuteAxis, 11.94, 1.75, 4.25, 0, "metal");
814
- r.flange(...secondsAxis, 7.25, 1.57, 3.45, 0, "metal");
815
- gearFace(r, secondsAxis, 13.7, secondsWheel, pose.seconds);
816
- r.flange(...escapeAxis, 7.26, 1.17, 3.55, 0, "metal");
817
- gearFace(r, escapeAxis, 13.7, escapePinion, pose.escape, "side");
818
-
819
- r.flange(...thirdAxis, 7.25, 1.6, 9.1, 0, "metal");
820
- gearFace(r, minuteAxis, 18.4, minuteWheel, pose.minute);
821
- gearFace(r, thirdAxis, 18.4, thirdPinion, pose.third, "side");
822
- r.flange(...thirdAxis, 19.6, 1.83, 4.64, 0, "metal");
823
- r.flange(...secondsAxis, 14.9, 1.55, 9.37, 0, "metal");
824
- r.flange(...escapeAxis, 14.95, 1.32, 6.0, 0, "metal");
825
- gearFace(r, escapeAxis, 22.7, { path: escapeWheel, bore: 2.2, rootRadius: 10.7 }, pose.escape);
826
- gearFace(r, thirdAxis, 26.2, thirdWheel, pose.third);
827
- gearFace(r, secondsAxis, 26.2, secondsPinion, pose.seconds, "side");
828
-
829
- clockBridge(r, offset(barrelAxis, 28.2, 2.1), barrelAxis, 16.2, 2.35);
830
- clockBridge(r, offset(thirdAxis, 26, -1.22), thirdAxis, 31.3, 2.14);
831
- drawBalance(r, pose.balance, pose.pallet);
832
- drawSeconds(r, pose);
833
- drawDial(r, pose);
839
+ clockRenderer ||= buildClock();
840
+ clockRenderer(r, distance);
834
841
  }
835
842
 
836
843
  function motionDistance(seconds) {