codex-copilot-dx 1.4.13 → 1.4.15

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.
@@ -1,9 +1,5 @@
1
1
  (() => {
2
- const fract = x => x - Math.floor(x);
3
- const clamp = x => Math.max(0, Math.min(1, x));
4
- const ease = x => { x = clamp(x); return x * x * (3 - 2 * x); };
5
- const mix = (a,b,t) => a+(b-a)*t;
6
- const project = (x,y,z=0) => [x+y*.52,152+y*.36-z];
2
+ "use strict";
7
3
  const palette = (inkColor, paperColor) => {
8
4
  const sampler = document.createElement("canvas");sampler.width=1;sampler.height=1;
9
5
  const sample = sampler.getContext("2d",{willReadFrequently:true});
@@ -16,347 +12,873 @@
16
12
  if (!colors.has(strength)) colors.set(strength, "rgb(" + paper.map((x,i) => Math.round(mix(x,ink[i],strength))).join(",") + ")");
17
13
  return colors.get(strength);
18
14
  };
19
- return { ink:inkColor,paper:paperColor,face:tone(.04),signal:inkColor,tone,
20
- stroke:tone(.66),shadow:tone(.10),base:tone(.32),top:tone(.13),side:tone(.25),end:tone(.39),edge:tone(.48) };
15
+ return { paper: paperColor, ink: inkColor, line: tone(.79), soft: tone(.58), metal: tone(.08),
16
+ side: tone(.17), flank: tone(.27), recess: tone(.37), shadow: tone(.07) };
21
17
  };
22
- function poly(c,points,fill,stroke,width=1) {
23
- c.beginPath();c.moveTo(...points[0]);for(let i=1;i<points.length;i++)c.lineTo(...points[i]);
24
- if(fill){c.closePath();c.fillStyle=fill;c.fill();}
25
- if(stroke){c.lineWidth=width;c.strokeStyle=stroke;c.stroke();}
26
- }
27
- function ellipse(c,x,y,rx,ry,fill,stroke,width=1) {
28
- c.beginPath();c.ellipse(x,y,rx,ry,0,0,Math.PI*2);
29
- if(fill){c.fillStyle=fill;c.fill();}
30
- if(stroke){c.lineWidth=width;c.strokeStyle=stroke;c.stroke();}
31
- }
32
- function beam(c,a,b,width,color) {
33
- c.lineCap="round";poly(c,[a,b],null,color,width);c.lineCap="butt";
34
- }
35
- function block(c,p,x,y,z,w,d,h,skin=p) {
36
- const a=project(x,y,z),f=project(x,y+d,z),g=project(x+w,y+d,z);
37
- const A=project(x,y,z+h),B=project(x+w,y,z+h),F=project(x,y+d,z+h),G=project(x+w,y+d,z+h);
38
- // The camera is above, in front of +Y and on the -X side.
39
- poly(c,[A,F,f,a],skin.end,p.stroke,.82);
40
- poly(c,[F,G,g,f],skin.side,p.stroke,.82);
41
- poly(c,[A,B,G,F],skin.top,p.stroke,.82);
42
- poly(c,[F,G],null,p.tone(.37),.72);
43
- }
44
- function plinth(c,p,x,y,w,d,h=4) {
45
- poly(c,[project(x-5,y+5),project(x+w+5,y+5),project(x+w+5,y+d+8),project(x-5,y+d+8)],p.shadow);
46
- block(c,p,x,y,0,w,d,h,{top:p.face,side:p.side,end:p.base});
47
- }
48
- function signal(c,p,x,y,z,live) {
49
- const [a,b]=project(x,y,z);
50
- ellipse(c,a,b,3.8,2.4,p.tone(.4));
51
- ellipse(c,a,b-.5,2.2,1.6,live?p.signal:p.tone(.60));
52
- }
53
- function roller(c,p,x,y,z,w,d) {
54
- block(c,p,x,y,z,w,d,8);
55
- const X=x+2,W=w-4;
56
- c.save();poly(c,[project(X,y,8+z),project(X+W,y,8+z),project(X+W,y+d,8+z),project(X,y+d,8+z)],p.tone(.19));c.clip();
57
- for(let a=x+5;a<x+w-3;a+=9){
58
- poly(c,[project(a,y+2,z+8),project(a,y+d-2,z+8)],null,p.tone(.45),2.7);
59
- poly(c,[project(a-.75,y+2,z+8),project(a-.75,y+d-2,z+8)],null,p.tone(.06),.85);
60
- }
61
- c.restore();
62
- for(const dy of [0,d-2])block(c,p,x,y+dy,z+8,w,2,2);
63
- for(const dx of [5,w-5]) {const [a,b]=project(x+dx,y+d,z+4);ellipse(c,a,b,1.8,1.8,p.ink,p.tone(.53),.5);}
64
- }
65
- // The rear plate goes behind the lane. The front plate and cap occlude
66
- // the lane, leaving a continuous aperture on the visible end.
67
- function beltGuard(c,p,x,y,length,depth,floor,ceiling,front) {
68
- if(!front){
69
- block(c,p,x,y,floor,length,3,ceiling-floor);
70
- return;
71
- }
72
- const edge=y+depth;
73
- block(c,p,x,edge-3,floor,length,3,ceiling-floor);
74
- block(c,p,x,y,ceiling,length,depth,3);
75
- const [a,b]=project(x+length*.54,edge,ceiling-5);
76
- ellipse(c,a,b,1.2,1.2,p.tone(.62));
77
- }
78
- const sweep = (q,start,end) => ease((q-start)/(end-start));
79
- function planeCircle(c,x,y,z,r,fill,stroke,width=1) {
80
- const [sx,sy]=project(x,y,z);
81
- c.save();c.transform(1,0,.52,.36,sx,sy);
82
- ellipse(c,0,0,r,r,fill,stroke,width);
83
- c.restore();
84
- }
85
- function cylinder(c,p,x,y,z,r,h,skin=p) {
86
- const near=Math.atan(.52);
87
- const rim=Array.from({length:13},(_,i)=>{
88
- const angle=near+i*Math.PI/12;
89
- return [x+r*Math.cos(angle),y+r*Math.sin(angle)];
90
- });
91
- const face=rim.map(([u,v])=>project(u,v,z+h));
92
- poly(c,[...face,...rim.reverse().map(([u,v])=>project(u,v,z))],skin.side,p.stroke,.8);
93
- planeCircle(c,x,y,z+h,r,skin.top,p.stroke,1.1);
94
- }
95
- function flange(c,p,x,y,z,width=24,shadow=true) {
96
- const half=width/2, depth=width*.32, h=6.5;
97
- const outline=[[-half,-depth+3],[-half+3,-depth],[half-3,-depth],[half,-depth+3],
98
- [half,depth-3],[half-3,depth],[-half+3,depth],[-half,depth-3]];
99
- const base=outline.map(([dx,dy])=>project(x+dx,y+dy,z));
100
- const top=outline.map(([dx,dy])=>project(x+dx,y+dy,z+h));
101
- const [sx,sy]=project(x,y,z);
102
- if(shadow)ellipse(c,sx+2,sy+1,half+3,depth*.48,p.shadow);
103
- for(const i of [7,6,5,4]){
104
- const j=(i+1)%outline.length;
105
- poly(c,[top[i],top[j],base[j],base[i]],p.tone(i===5?.56:.41),p.stroke,.65);
106
- }
107
- poly(c,top,p.tone(.07),p.tone(.77),.95);
108
- poly(c,[top[0],top[1],top[2],top[3]],null,p.paper,.85);
109
- poly(c,[top[7],top[6],top[5],top[4]],null,p.tone(.25),.8);
110
- const [cx,cy]=project(x,y,z+h);
111
- c.save();c.transform(1,0,.52,.36,cx,cy);
112
- ellipse(c,0,0,5,5,p.tone(.22),p.tone(.64),.8);
113
- ellipse(c,0,0,3.9,3.9,p.ink);
114
- for(const side of [-1,1]) {
115
- ellipse(c,side*(half-4),0,1.25,1.25,p.ink);
116
- }
117
- c.restore();
118
- }
119
- function assembly(c,p,t,running,reduced,layer) {
120
- const moving=running&&!reduced;
121
- const q=moving?fract(t/1.53):.93;
122
- const travel=sweep(q,.02,.37), step=108, pressX=174, lane=48, deck=29;
123
- const insertion=sweep(q,.56,.63);
124
- const pressTip=mix(72,40.5,sweep(q,.42,.56))-3*insertion
125
- +35*sweep(q,.68,.85);
126
- layer("base",c=>{
127
- plinth(c,p,11,4,353,82,5);
128
- for(const x of [51,110,239,305]){
129
- for(const y of [34,56])block(c,p,x,y,5,8,7,16);
18
+ const diagonal = Math.SQRT1_2;
19
+ const tau = Math.PI * 2;
20
+ const wrap = (value, period) => ((value % period) + period) % period;
21
+ const mix = (a, b, amount) => a + (b - a) * amount;
22
+ function segment(value, start, end) {
23
+ const t = Math.min(1, Math.max(0, (value - start) / (end - start)));
24
+ return t * t * (3 - 2 * t);
25
+ }
26
+ const project = ([x, y, z]) => [(x - y) * diagonal, (x + y) / 2 - z * diagonal];
27
+
28
+ function renderer(context, width, height, colors, kind) {
29
+ const scale = Math.min(width / (kind === "clock" ? 208 : 305), height / (kind === "clock" ? 161 : kind === "rotary" ? 190 : 218));
30
+ const ox = width / 2 + (kind === "rotary" ? 3 : kind === "clock" ? -3 : -5) * scale;
31
+ const oy = height / 2 + (kind === "rotary" ? 20 : kind === "clock" ? 17 : 7) * scale;
32
+ context.clearRect(0, 0, width, height);
33
+ context.lineJoin = "round";
34
+ context.lineCap = "round";
35
+ context.save();
36
+ context.translate(ox, oy);
37
+ context.scale(scale, scale);
38
+
39
+ function shape(vertices, fill, stroke = "line", weight = 0.62) {
40
+ const points = vertices.map(project);
41
+ context.beginPath();
42
+ context.moveTo(...points[0]);
43
+ for (const point of points.slice(1)) context.lineTo(...point);
44
+ if (fill) {
45
+ context.closePath();
46
+ context.fillStyle = colors[fill];
47
+ context.fill();
130
48
  }
131
- for(const x of [16,329])beltGuard(c,p,x,27,28,44,5,44,false);
132
- roller(c,p,23,31,21,121,34);
133
- roller(c,p,204,31,21,144,34);
134
- // The lower die and the transfer guides share the conveyor deck height.
135
- block(c,p,140,31,13,68,34,16);
136
- for(const y of [31,63])block(c,p,141,y,29,67,2,2);
137
- block(c,p,145,34,5,59,27,8,{top:p.top,side:p.base,end:p.end});
138
-
139
- block(c,p,147,10,5,9,13,103);
140
- block(c,p,192,10,5,9,13,103);
141
- block(c,p,143,6,5,18,22,6);
142
- block(c,p,187,6,5,18,22,6);
143
- block(c,p,146,17,95,55,50,12);
144
- block(c,p,155,30,107,38,33,12,{top:p.face,side:p.base,end:p.end});
145
- block(c,p,167,42,69,14,12,26);
146
- for(const x of [155,193]){
147
- block(c,p,x,35,72,3,7,23);
148
- block(c,p,x,53,72,3,7,23);
49
+ if (stroke) {
50
+ context.strokeStyle = colors[stroke];
51
+ context.lineWidth = weight;
52
+ context.stroke();
149
53
  }
150
- poly(c,[project(192,24,111),project(198,24,111),project(202,31,105),
151
- project(202,45,104)],null,p.tone(.58),2.5);
152
- const hatch=Array.from({length:6},(_,i)=>151+i*8);
153
- for(const x of hatch)poly(c,[project(x,67,96),project(x+4,67,104)],null,p.tone(.48),1.1);
154
- });
155
- signal(c,p,187,53,119,moving&&q>.42&&q<.69);
156
-
157
- for(const i of [-1,0,1,2]){
158
- const x=pressX+(i+travel-1)*step;
159
- if(x<31||x>343)continue;
160
- flange(c,p,x,lane,deck,26);
161
- const lip=i>0?2:i===0?5-3*insertion:5;
162
- cylinder(c,p,x,lane,deck+6.5,5.5,lip,{top:p.tone(.07),side:p.edge,end:p.edge});
163
- planeCircle(c,x,lane,deck+6.5+lip,2.7,p.ink);
164
- }
165
- block(c,p,171,45,pressTip+3,6,6,78-(pressTip+3));
166
- block(c,p,164,40,pressTip,20,16,3,{top:p.top,side:p.end,end:p.base});
167
- layer("guard",c=>{
168
- for(const x of [16,329])beltGuard(c,p,x,27,28,44,5,44,true);
54
+ }
55
+
56
+ function line(from, to, stroke = "line", weight = 0.46) {
57
+ shape([from, to], null, stroke, weight);
58
+ }
59
+
60
+ function box(x, y, z, w, d, h, top = "paper", front = "side", end = "metal") {
61
+ const a = [x, y, z + h], b = [x + w, y, z + h];
62
+ const c = [x + w, y + d, z + h], e = [x, y + d, z + h];
63
+ shape([b, [x + w, y, z], [x + w, y + d, z], c], end);
64
+ shape([e, c, [x + w, y + d, z], [x, y + d, z]], front);
65
+ shape([a, b, c, e], top);
66
+ }
67
+
68
+ function plane(x, y, z, turn, draw) {
69
+ context.save();
70
+ const point = project([x, y, z]);
71
+ context.transform(diagonal, 0.5, -diagonal, 0.5, ...point);
72
+ context.rotate(turn);
73
+ draw(context);
74
+ context.restore();
75
+ }
76
+
77
+ function outline(path, fill, stroke = "line", weight = 0.54) {
78
+ if (fill) {
79
+ context.fillStyle = colors[fill];
80
+ context.fill(path, "evenodd");
81
+ }
82
+ if (stroke) {
83
+ context.strokeStyle = colors[stroke];
84
+ context.lineWidth = weight;
85
+ context.stroke(path);
86
+ }
87
+ }
88
+
89
+ function circle(x, y, z, radius, fill, stroke = "line", weight = 0.49) {
90
+ plane(x, y, z, 0, () => {
91
+ const path = new Path2D();
92
+ path.arc(0, 0, radius, 0, tau);
93
+ outline(path, fill, stroke, weight);
94
+ });
95
+ }
96
+
97
+ function hole(x, y, z, radius = 1.15) {
98
+ circle(x, y, z, radius, "flank", "soft", 0.37);
99
+ line([x - radius * 0.57, y, z], [x + radius * 0.57, y, z], "soft", 0.35);
100
+ }
101
+
102
+ function flange(x, y, z, radius, height, bore = 0, top = "paper") {
103
+ const start = -Math.PI / 4;
104
+ const arc = Array.from({ length: 16 }, (_, i) => {
105
+ const a = start + Math.PI * i / 15;
106
+ return [x + radius * Math.cos(a), y + radius * Math.sin(a)];
107
+ });
108
+ shape([...arc.map(([px, py]) => [px, py, z]), ...arc.reverse().map(([px, py]) => [px, py, z + height])], "side");
109
+ circle(x, y, z + height, radius, top);
110
+ if (bore) {
111
+ circle(x, y, z + height, bore, "recess");
112
+ circle(x, y, z + height, bore + 1.3, null, "soft", 0.39);
113
+ }
114
+ }
115
+
116
+ function shaftCap(x, y, z, radius, phase, fill = "metal") {
117
+ const point = project([x, y, z]);
118
+ context.save();
119
+ context.transform(diagonal, 0.5, 0, -diagonal, ...point);
120
+ const face = new Path2D();
121
+ face.arc(0, 0, radius, 0, tau);
122
+ outline(face, fill);
123
+ const hub = new Path2D();
124
+ hub.arc(0, 0, radius * 0.34, 0, tau);
125
+ outline(hub, "flank", "line", 0.4);
126
+ const slot = new Path2D();
127
+ slot.moveTo(Math.cos(phase) * radius * 0.42, Math.sin(phase) * radius * 0.42);
128
+ slot.lineTo(Math.cos(phase) * radius * 0.82, Math.sin(phase) * radius * 0.82);
129
+ outline(slot, null, "ink", 0.62);
130
+ context.restore();
131
+ }
132
+
133
+ return { context, colors, shape, line, box, plane, outline, circle, hole, flange, shaftCap };
134
+ }
135
+
136
+ const beltHeight = 34.7;
137
+ const station = -12;
138
+ const palletHeight = beltHeight + 2.6;
139
+ const pitch = 42;
140
+
141
+ function platform(r, x, y, w, d) {
142
+ r.shape([[x + 3, y + 5, 0], [x + w + 5, y + 5, 0],
143
+ [x + w + 5, y + d + 6, 0], [x + 3, y + d + 6, 0]], "shadow", null);
144
+ r.box(x, y, 1, w, d, 3, "metal", "flank");
145
+ for (const dx of [6, w - 6]) for (const dy of [5, d - 5]) r.hole(x + dx, y + dy, 4.05);
146
+ }
147
+
148
+ function trackSupport(r, x, y, width) {
149
+ for (const edge of [y - width + 3, y + width - 7]) {
150
+ r.box(x - 4, edge - 2, 4, 13, 9, 2, "metal");
151
+ r.hole(x - 1.9, edge + 4.9, 6.03);
152
+ r.hole(x + 6.8, edge + 4.9, 6.03);
153
+ r.box(x, edge, 6, 5, 5, 19, "metal");
154
+ r.line([x + 2.5, edge + 5, 8], [x + 2.5, edge + 5, 24], "soft");
155
+ }
156
+ r.box(x - 1, y - width + 2, 23, 7, width * 2 - 4, 3, "metal");
157
+ }
158
+
159
+ function cover(r, x, y, width, length) {
160
+ const z = beltHeight;
161
+ r.box(x, y - width - 3, z - 2, length, 3, 15, "metal");
162
+ r.box(x, y + width, z - 3, length, 3, 16, "metal");
163
+ r.box(x, y - width - 3, z + 13, length, 2 * width + 6, 2.5, "paper");
164
+ for (const dx of [2.7, length - 2.7]) for (const dy of [-width, width]) r.hole(x + dx, y + dy, z + 15.53);
165
+ for (let dx = length / 2 - 4; dx < length / 2 + 6; dx += 2) {
166
+ r.line([x + dx, y - 4, z + 15.54], [x + dx, y + 4, z + 15.54], "soft", 0.6);
167
+ }
168
+ }
169
+
170
+ function belt(r, left, right, y, width, travel, payload = () => {}) {
171
+ const drum = 5.7, axle = 29, straight = right - left;
172
+ const round = Math.PI * drum, loop = 2 * (straight + round);
173
+ const count = Math.ceil(loop / 8);
174
+ const z = beltHeight;
175
+ r.box(left - 4, y - width - 3, 24, straight + 8, 3, 10, "metal");
176
+ r.box(left, y - width, axle - drum, straight, width * 2, 2, "metal", "flank");
177
+ const band = Array.from({ length: 13 }, (_, index) => {
178
+ const a = Math.PI * index / 12;
179
+ return [right + drum * Math.sin(a), y + width, axle + drum * Math.cos(a)];
169
180
  });
181
+ r.shape([...band, ...band.slice().reverse().map(([x, , zz]) => [x, y - width, zz])], "flank");
182
+ r.shape([[left, y - width, z], [right, y - width, z], [right, y + width, z], [left, y + width, z]], "metal");
183
+ for (let i = 0; i < count; i++) {
184
+ const s = wrap(i * loop / count + travel, loop);
185
+ if (s >= straight + round) continue;
186
+ const a = (s - straight) / drum;
187
+ const x = s < straight ? left + s : right + drum * Math.sin(a);
188
+ const zz = s < straight ? z : axle + drum * Math.cos(a);
189
+ r.line([x, y - width + 1.3, zz], [x, y + width - 1.3, zz], "soft");
190
+ }
191
+ payload();
192
+ r.box(left - 4, y + width, 24, straight + 8, 3, 9.8, "paper", "side");
193
+ r.line([left + 7, y + width + 3.02, 26.3], [right - 7, y + width + 3.02, 26.3], "soft", 0.51);
194
+ r.shaftCap(left, y + width + 3.25, axle, 3.6, -travel / drum);
195
+ r.shaftCap(right, y + width + 3.25, axle, 4.1, -travel / drum);
170
196
  }
171
- function sorter(c,p,t,running,reduced,layer) {
172
- const moving=running&&!reduced, phase=moving?t*1.03:0;
173
- const pathY=x=>29+39*ease((x-152)/70);
174
- layer("base",c=>{
175
- plinth(c,p,16,5,334,84);
176
- for(const x of [37,138,248,310]){
177
- for(const y of [17,35])block(c,p,x,y,4,7,6,16);
178
- }
179
- for(const x of [224,269,310]){
180
- for(const y of [56,74])block(c,p,x,y,4,7,6,16);
197
+
198
+ function pallet(r, x, y, width = 12) {
199
+ r.box(x - 6.3, y - width / 2, beltHeight, 12.6, width, 2.6, "paper");
200
+ }
201
+
202
+ function workpiece(r, x, y, z, seated = false) {
203
+ r.flange(x, y, z, 5, 1.4, 0, "metal");
204
+ r.flange(x, y, z + 1.4, 3.9, 4.4, seated ? 1.3 : 2.65, seated ? "metal" : "paper");
205
+ if (seated) r.circle(x, y, z + 5.84, 2.45, null, "soft", 0.35);
206
+ }
207
+
208
+ function motor(r, x, y) {
209
+ r.box(x - 9, y - 1, 18, 19, 10, 2, "metal");
210
+ r.box(x - 7, y, 20, 15, 10, 12, "metal", "flank");
211
+ for (let dx = -5; dx <= 6; dx += 2.4) {
212
+ r.line([x + dx, y + 3, 32.04], [x + dx, y + 10, 32.04], "soft", 0.6);
213
+ r.line([x + dx, y + 10.03, 32], [x + dx, y + 10.03, 21.5], "soft", 0.6);
214
+ }
215
+ }
216
+
217
+ function indexCycle(distance) {
218
+ const time = (distance + 0.16) / 2.12;
219
+ const step = Math.floor(time), phase = time - step;
220
+ const advance = pitch * segment(phase, 0, 0.26);
221
+ return { step, phase, advance, travel: pitch * step + advance };
222
+ }
223
+
224
+ function transferPose(phase, from, to) {
225
+ const low = palletHeight, high = low + 19;
226
+ const lift = segment(phase, 0.27, 0.38) - segment(phase, 0.43, 0.55)
227
+ + segment(phase, 0.69, 0.79) - segment(phase, 0.85, 0.93);
228
+ const side = segment(phase, 0.55, 0.69) - segment(phase, 0.93, 1);
229
+ const grip = segment(phase, 0.38, 0.43) - segment(phase, 0.79, 0.85);
230
+ const y = mix(from, to, side);
231
+ const z = mix(high, low, lift);
232
+ if (phase < 0.43) return { y, z, grip, part: [from, low] };
233
+ if (phase < 0.79) return { y, z, grip, part: [y, z] };
234
+ return { y, z, grip, part: [to, low] };
235
+ }
236
+
237
+ function jaw(r, x, y, z, grip) {
238
+ const gap = mix(5.9, 3.9, grip);
239
+ r.box(x - 4.8, y - 4.8, z + 6.2, 9.6, 9.6, 5, "metal");
240
+ for (const side of [-1, 1]) {
241
+ const edge = x + side * gap;
242
+ r.box(edge - (side < 0 ? 1.7 : 0), y - 2.3, z + 2.3, 1.7, 4.6, 5.6, "flank");
243
+ r.box(edge - (side < 0 ? 2 : 0), y - 2.3, z + 2.1, 2, 4.6, 1.5, "side");
244
+ }
245
+ r.hole(x, y, z + 11.26, 1.25);
246
+ }
247
+
248
+ function armLink(r, a, b, height, half) {
249
+ const dx = b[0] - a[0], dy = b[1] - a[1];
250
+ const length = Math.hypot(dx, dy), nx = -dy * half / length, ny = dx * half / length;
251
+ const edge = (point, sign, z) => [point[0] + nx * sign, point[1] + ny * sign, z];
252
+ const front = nx + ny > 0 ? 1 : -1;
253
+ r.shape([edge(a, front, height), edge(b, front, height),
254
+ edge(b, front, height - 4.7), edge(a, front, height - 4.7)], "side");
255
+ r.shape([edge(a, -1, height), edge(b, -1, height), edge(b, 1, height), edge(a, 1, height)], "paper");
256
+ r.line([a[0], a[1], height + 0.02], [b[0], b[1], height + 0.02], "soft", 0.51);
257
+ }
258
+
259
+ function scaraHead(r, shoulder, x, pose) {
260
+ const wrist = [x, pose.y];
261
+ const dx = wrist[0] - shoulder[0], dy = wrist[1] - shoulder[1];
262
+ const link = 30, reach = Math.hypot(dx, dy);
263
+ const lift = Math.sqrt(link * link - reach * reach / 4);
264
+ const elbow = [shoulder[0] + dx / 2 - dy * lift / reach, shoulder[1] + dy / 2 + dx * lift / reach];
265
+ jaw(r, x, pose.y, pose.z, pose.grip);
266
+ r.flange(x, pose.y, pose.z + 11.2, 1.7, 70 - pose.z - 11.2, 0, "metal");
267
+ armLink(r, elbow, wrist, 73, 4.6);
268
+ r.flange(x, pose.y, 70, 4.5, 5, 1.45, "metal");
269
+ armLink(r, shoulder, elbow, 78, 5.4);
270
+ r.flange(...elbow, 72.2, 5.3, 7.2, 1.7, "metal");
271
+ r.flange(...shoulder, 74, 6.5, 6, 2, "metal");
272
+ }
273
+
274
+ function press(r, x, y, phase, partTop, top = 73) {
275
+ const stroke = segment(phase, 0.31, 0.52) - segment(phase, 0.65, 0.83);
276
+ const tip = mix(partTop + 18, partTop, stroke);
277
+ r.flange(x, y, tip, 2.4, top - tip, 0, "side");
278
+ r.box(x - 5.4, y - 4.7, top - 6, 10.8, 9.4, 10, "metal");
279
+ r.hole(x, y, top + 4.04, 1.2);
280
+ }
281
+
282
+ function singleLine(r, distance, robotic) {
283
+ const cycle = indexCycle(distance);
284
+ const width = robotic ? 19 : 13;
285
+ const shoulder = [-26, -40];
286
+ const pose = transferPose(cycle.phase, -8.5, 8.5);
287
+ const top = robotic ? 80 : 77;
288
+
289
+ r.layer("bed", r => {
290
+ platform(r, -121, robotic ? -50 : -40, 242, robotic ? 79 : 65);
291
+ if (robotic) {
292
+ r.box(-36, -48, 4, 20, 17, 3, "paper");
293
+ for (const x of [-33, -19]) for (const y of [-45, -34]) r.hole(x, y, 7.04);
294
+ r.flange(...shoulder, 7, 6.9, 5, 0, "metal");
295
+ r.flange(...shoulder, 12, 4.6, 65, 0, "metal");
296
+ r.flange(...shoulder, 59, 6.25, 11.5, 0, "side");
297
+ } else {
298
+ r.box(station - 10, -37, 4, 20, 14, 3);
299
+ r.hole(station - 7, -33, 7.02);
300
+ r.hole(station + 7, -33, 7.02);
301
+ r.box(station - 6, -35, 7, 12, 9, top - 10, "metal");
302
+ r.line([station - 3, -25.95, 10], [station - 3, -25.95, top - 5], "soft");
181
303
  }
182
- for(const [x,y] of [[169,37],[195,54]])block(c,p,x,y,4,7,6,16);
183
- roller(c,p,23,15,20,309,28);
184
- // The transfer deck follows the polished guide path.
185
- const bars=Array.from({length:10},(_,i)=>151+8*i);
186
- const back=bars.map(x=>project(x,pathY(x)-12,28));
187
- const front=bars.map(x=>project(x,pathY(x)+12,28));
188
- const skirt=bars.map(x=>project(x,pathY(x)+12,20));
189
- poly(c,[...front,...skirt.reverse()],p.side,p.stroke,.85);
190
- poly(c,[...back,...front.slice().reverse()],p.tone(.21),p.stroke,.85);
191
- for(const x of bars){
192
- const y=pathY(x);
193
- poly(c,[project(x,y-10,28),project(x,y+10,28)],null,p.edge,2);
194
- poly(c,[project(x+.7,y-10,28),project(x+.7,y+10,28)],null,p.top,.75);
304
+ for (const x of [-83, -37, 31, 82]) trackSupport(r, x, 0, width);
305
+ });
306
+ belt(r, -108, 109, 0, width, cycle.travel, () => {
307
+ for (let i = 0; i < 5; i++) {
308
+ const x = -102 + wrap(i * pitch + 6 + cycle.travel, 5 * pitch);
309
+ const indexed = cycle.phase >= 0.26;
310
+ const atStation = indexed && Math.abs(x - station) < 0.1;
311
+ const processed = indexed ? x > station + 0.1 : x >= station + cycle.advance - 0.1;
312
+ pallet(r, x, 0, robotic ? 29 : 12);
313
+ if (robotic) {
314
+ for (const y of [-8.5, 8.5]) r.circle(x, y, palletHeight + 0.03, 5, null, "soft", 0.41);
315
+ const [y, z] = atStation ? pose.part : [processed ? 8.5 : -8.5, palletHeight];
316
+ workpiece(r, x, y, z);
317
+ } else {
318
+ workpiece(r, x, 0, palletHeight, processed || (atStation && cycle.phase >= 0.52));
319
+ }
195
320
  }
196
- roller(c,p,211,54,20,121,28);
197
- block(c,p,118,9,4,6,9,71);
198
- block(c,p,118,46,4,6,9,71);
199
- block(c,p,114,10,75,15,45,7);
200
- block(c,p,119,21,66,8,24,9);
201
321
  });
202
- const idle=[.06,.23,.49,.65,.79,.92];
203
- const parts=idle.map((rest,i)=>{
204
- const q=moving?fract(phase+i/6):rest;
205
- const x=27+297*q;
206
- const y=i%2?pathY(x):29;
207
- return {x,y,q};
322
+ r.layer("guards", r => {
323
+ cover(r, -113, 0, width, 24);
324
+ cover(r, 90, 0, width, 25);
325
+ motor(r, 107, width + 5);
208
326
  });
209
- const scanned=parts.some(part=>Math.abs(part.x-122)<13);
210
- const divert=parts.reduce((s,part,i)=>i%2?Math.max(s,
211
- ease((part.x-143)/13)*ease((206-part.x)/15)):s,0);
212
- const pivot=project(152,41,38),tip=project(152+29*divert,41-16*divert,38);
213
- block(c,p,149,38,22,6,6,16);
214
- beam(c,pivot,tip,4,p.tone(.36));beam(c,pivot,tip,1,p.tone(.77));
215
- parts.sort((a,b)=>a.y-b.y||a.x-b.x).forEach(({x,y,q})=>{
216
- c.globalAlpha=moving?Math.min(ease(q/.047),ease((1-q)/.054)):1;
217
- flange(c,p,x,y,28);
327
+ if (robotic) {
328
+ scaraHead(r, shoulder, station, pose);
329
+ } else {
330
+ r.box(station - 6, -35, top - 6, 12, 41, 6, "paper");
331
+ r.line([station - 2.8, -31, top + 0.03], [station - 2.8, 2.7, top + 0.03], "soft");
332
+ for (const y of [-31, 2.4]) r.hole(station + 2.8, y, top + 0.04, 1.1);
333
+ press(r, station, 0, cycle.phase, palletHeight + 5.8, top - 8);
334
+ }
335
+ }
336
+
337
+ function sortPose(distance) {
338
+ const time = (distance + 0.13) / 1.86;
339
+ const step = Math.floor(time), phase = time - step;
340
+ const lane = step % 2 ? 23 : -23;
341
+ const y = lane * (segment(phase, 0.34, 0.55) - segment(phase, 0.74, 0.94));
342
+ const x = -104 + 78 * segment(phase, 0.04, 0.34) + 128 * segment(phase, 0.55, 0.94);
343
+ return { x, y, lane, step, phase, incoming: 78 * segment(phase, 0.04, 0.34) };
344
+ }
345
+
346
+ function sorter(r, distance) {
347
+ const { x, y, lane, phase, step, incoming } = sortPose(distance);
348
+ const partY = phase <= 0.55 ? y : lane;
349
+ const max = 102;
350
+ platform(r, -119, -44, 234, 88);
351
+ for (const sx of [-85, -52]) trackSupport(r, sx, 0, 11);
352
+ for (const cy of [-23, 23]) for (const sx of [11, 57, 91]) trackSupport(r, sx, cy, 10);
353
+
354
+ for (const sx of [-35, -17]) {
355
+ r.box(sx - 2.5, -36, 4, 8, 72, 15, "metal", "side");
356
+ r.box(sx, -36, 19, 3, 72, 5, "paper");
357
+ for (const edge of [-34, 31]) r.hole(sx + 1.5, edge, 24.02, 0.8);
358
+ }
359
+ belt(r, -107, -45, 0, 11, step * 78 + incoming, () => {
360
+ if (x <= -39) {
361
+ pallet(r, x, 0);
362
+ workpiece(r, x, 0, palletHeight);
363
+ }
218
364
  });
219
- c.globalAlpha=1;
220
- signal(c,p,123,33,82,running&&scanned);
221
- if(moving&&scanned)poly(c,[project(122,18,35),project(122,39,35)],null,p.signal,1.05);
222
- for(const y of [15,54]){
223
- block(c,p,324,y+25,20,7,3,13);
224
- signal(c,p,327,y+26.5,33,moving&&parts.some(part=>part.x>303&&Math.abs(part.y-y-14)<9));
225
- }
226
- }
227
- function gantry(c,p,t,running,reduced,layer) {
228
- const moving=running&&!reduced;
229
- const q=moving?fract(t/1.53):.01;
230
- const from=94,to=267,lane=51,deck=29;
231
- const clear=79,pick=43;
232
- const carriageX=from+(to-from)*(sweep(q,.34,.60)-sweep(q,.86,1));
233
- const carriageZ=clear-(clear-pick)*(sweep(q,.025,.18)-sweep(q,.23,.34)
234
- +sweep(q,.60,.71)-sweep(q,.77,.86));
235
- const grasp=sweep(q,.18,.23)-sweep(q,.72,.77);
236
- const held=q>=.23&&q<.72;
237
- const partZ=carriageZ-(pick-deck), feed=sweep(q,.33,.92), sent=sweep(q,.79,1);
238
- layer("base",c=>{
239
- plinth(c,p,11,4,351,84,5);
240
- for(const x of [54,303]) {
241
- block(c,p,x-6,9,5,25,24,6);
242
- block(c,p,x,13,11,13,16,93);
243
- poly(c,[project(x+1,29,32),project(x+21,29,11),project(x+1,29,11)],p.side,p.stroke,.8);
365
+ r.box(-37, y - 10.7, 24, 20, 21.4, 9.5, "paper", "side");
366
+ const shuttleTravel = step * 89 + incoming + Math.max(0, Math.min(11, x + 26));
367
+ belt(r, -33, -21, y, 9, shuttleTravel, () => {
368
+ if (x > -39 && x <= -15) {
369
+ pallet(r, x, partY);
370
+ workpiece(r, x, partY, palletHeight);
244
371
  }
245
- for(const x of [45,98,257,312]){
246
- for(const y of [38,59])block(c,p,x,y,5,8,6,16);
372
+ });
373
+ for (const cy of [-23, 23]) {
374
+ const completed = Math.floor((step + (cy < 0 ? 1 : 0)) / 2);
375
+ const outgoing = cy === lane ? Math.max(0, x + 15) : 0;
376
+ belt(r, -9, 107, cy, 10, completed * 117 + outgoing, () => {
377
+ if (x > -15 && x < max + 0.1 && cy === lane) {
378
+ pallet(r, x, cy);
379
+ workpiece(r, x, cy, palletHeight);
380
+ }
381
+ });
382
+ cover(r, 90, cy, 10, 22);
383
+ }
384
+ cover(r, -113, 0, 11, 21);
385
+ }
386
+
387
+ function gantry(r, distance) {
388
+ const cycle = indexCycle(distance);
389
+ const far = -23, near = 23;
390
+ const pose = transferPose(cycle.phase, far, near);
391
+ const z = 79;
392
+ platform(r, -118, -51, 233, 103);
393
+ function column(y) {
394
+ r.box(station - 10, y - 7, 4, 20, 14, 3);
395
+ for (const x of [station - 7, station + 7]) r.hole(x, y + 3.7, 7.03);
396
+ r.box(station - 5.6, y - 4, 7, 11.2, 8, z - 10, "metal");
397
+ r.line([station - 2.4, y + 4.03, 10], [station - 2.4, y + 4.03, z - 5], "soft");
398
+ }
399
+ column(-44);
400
+ for (const y of [far, near]) {
401
+ for (const x of [-86, -41, 21, 75]) trackSupport(r, x, y, 10);
402
+ belt(r, -108, 108, y, 10, cycle.travel, () => {
403
+ for (let i = 0; i < 5; i++) {
404
+ const x = -102 + wrap(i * pitch + 6 + cycle.travel, 5 * pitch);
405
+ const indexed = cycle.phase >= 0.26;
406
+ const atStation = indexed && Math.abs(x - station) < 0.1;
407
+ const processed = indexed ? x > station + 0.1 : x >= station + cycle.advance - 0.1;
408
+ pallet(r, x, y);
409
+ if (!atStation && (processed ? near : far) === y) workpiece(r, x, y, palletHeight);
410
+ }
411
+ });
412
+ cover(r, -113, y, 10, 21);
413
+ cover(r, 90, y, 10, 21);
414
+ }
415
+ if (cycle.phase >= 0.26) workpiece(r, station, ...pose.part);
416
+ jaw(r, station, pose.y, pose.z, pose.grip);
417
+ r.flange(station, pose.y, pose.z + 11.2, 1.9, z - pose.z - 11.2, 0, "metal");
418
+ column(44);
419
+ r.box(station - 6.7, -49, z - 6, 13.4, 98, 6, "paper", "side");
420
+ for (const x of [station - 4.2, station + 4.2]) {
421
+ r.line([x, -45, z + 0.04], [x, 45, z + 0.04], "soft", 0.65);
422
+ for (const y of [-45, 45]) r.hole(x, y, z + 0.05, 0.8);
423
+ }
424
+ r.box(station - 7.4, pose.y - 5.4, z - 7.3, 14.8, 10.8, 9.4, "metal");
425
+ r.hole(station, pose.y, z + 2.13, 1.6);
426
+ r.box(station - 6, 43, z, 12, 8, 4.4, "flank");
427
+ }
428
+
429
+ function rotary(r, distance) {
430
+ const { step, phase, advance } = indexCycle(distance);
431
+ const slot = tau / 6, rotation = (step + advance / pitch) * slot;
432
+ const bearing = 26, radius = 47, top = 29.8;
433
+ const angle = -Math.PI / 3, orbit = 34;
434
+ const axis = [Math.cos(angle) * orbit, Math.sin(angle) * orbit];
435
+ r.layer("table", r => {
436
+ platform(r, -57, -62, 114, 116);
437
+ r.box(11, -59, 4, 20, 13, 3, "paper");
438
+ for (const x of [14, 28]) r.hole(x, -54, 7.04);
439
+ r.box(15, -57, 7, 12, 9, 67, "metal");
440
+ r.line([18, -47.97, 10], [18, -47.97, 71], "soft");
441
+ r.flange(0, 0, 4, bearing + 7, 4, 0, "metal");
442
+ r.flange(0, 0, 8, bearing, 15.8, 0, "side");
443
+ for (let i = 0; i < 10; i++) {
444
+ const a = -Math.PI / 4 + Math.PI * i / 9;
445
+ const x = bearing * Math.cos(a), y = bearing * Math.sin(a);
446
+ r.line([x, y, 8.7], [x, y, 22.9], "soft", 0.61);
247
447
  }
248
- for(const x of [17,329])beltGuard(c,p,x,32,25,40,5,39,false);
249
- roller(c,p,27,35,21,93,32);
250
- roller(c,p,241,35,21,107,32);
448
+ r.flange(0, 0, 23.8, radius, 6, 0, "metal");
251
449
  });
252
- if(held) {
253
- // The load casts its shadow onto the bed or onto the lower machine base.
254
- const surface=carriageX<119||carriageX>245?deck:5;
255
- const [x,y]=project(carriageX,lane,surface);
256
- ellipse(c,x+2,y,13,3.8,p.shadow);
257
- }
258
- if(q<.23)flange(c,p,from,lane,deck,21);
259
- for(const x of [from-41+41*feed,from-82+41*feed]){
260
- if(x>=30)flange(c,p,x,lane,deck,21);
261
- }
262
- if(q>=.72&&to+91*sent<342)flange(c,p,to+91*sent,lane,deck,21);
263
-
264
- layer("beam",c=>{
265
- block(c,p,48,20,100,273,34,13);
266
- for(const z of [103,109]) {
267
- poly(c,[project(52,54,z),project(317,54,z)],null,p.tone(.60),1.5);
450
+ r.circle(0, 0, top + 0.01, 44, null, "soft", 0.6);
451
+ const fixtures = [];
452
+ for (let i = 0; i < 6; i++) {
453
+ const a = angle + i * slot + rotation;
454
+ fixtures.push({ x: Math.cos(a) * orbit, y: Math.sin(a) * orbit, i });
455
+ const mark = a + slot / 2;
456
+ const direction = [Math.cos(mark), Math.sin(mark)];
457
+ r.line([...direction.map(v => v * 42), top + 0.02], [...direction.map(v => v * 46), top + 0.02], "soft", 0.7);
458
+ }
459
+ r.flange(0, 0, top, 10, 3.1, 2.4, "paper");
460
+ for (const { x, y, i } of fixtures.sort((a, b) => a.x + a.y - b.x - b.y)) {
461
+ const arrival = (6 - i) % 6;
462
+ const seated = step + (phase >= 0.52 ? 1 : 0) > ((arrival + 5) % 6);
463
+ r.flange(x, y, top, 7.8, 2.5, 0, "paper");
464
+ workpiece(r, x, y, top + 2.5, seated);
465
+ }
466
+ r.box(15, -57, 72, 12, 34, 5, "paper");
467
+ for (const y of [-53, -26]) r.hole(21, y, 77.04, 1.25);
468
+ press(r, ...axis, phase, top + 8.3, 67);
469
+ }
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));
268
495
  }
269
- for(let x=66;x<316;x+=19){
270
- const [a,b]=project(x,54,106);
271
- ellipse(c,a,b,1.3,1.3,p.tone(.68));
496
+ for (let j = 4; j >= 0; j--) {
497
+ const radius = rootFlank + (outerRadius - rootFlank) * j / 4;
498
+ point(radius, angle + halfAngle(radius));
272
499
  }
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
+ path.closePath();
515
+ }
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
+ 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
+ }
606
+
607
+ const initialClock = clockPose(0);
608
+
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));
613
+ }
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
+ 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);
630
+ }
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
+
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);
273
653
  });
274
- const cable=[project(315,38,116),project(carriageX+20,38,116),
275
- project(carriageX+14,38,113),project(carriageX+10,38,108)];
276
- poly(c,cable,null,p.tone(.43),3.4);
277
- poly(c,cable,null,p.tone(.69),.85);
278
- block(c,p,carriageX-10,32,90,20,25,19,{top:p.face,side:p.base,end:p.end});
279
- block(c,p,carriageX-3,47,carriageZ+3,6,8,90-carriageZ-3);
280
- block(c,p,carriageX-11,44,carriageZ,22,14,4);
281
- if(held)flange(c,p,carriageX,lane,partZ,21,false);
282
- for(const sign of [-1,1]){
283
- const jawX=carriageX+sign*mix(14.5,11.8,grasp);
284
- block(c,p,jawX-1.3,46,carriageZ-12,2.6,10,12);
285
- }
286
- layer("guard",c=>{
287
- for(const x of [17,329])beltGuard(c,p,x,32,25,40,5,39,true);
654
+ }
655
+
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
+ }
681
+
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
+ }
703
+
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];
288
715
  });
289
- signal(c,p,306,39,113,held&&moving);
290
- }
291
- function rotary(c,p,t,running,reduced,layer) {
292
- const moving=running&&!reduced;
293
- const phase=moving?t/1.04:.32;
294
- const u=fract(phase), stationAngle=Math.PI/3;
295
- const angle=(Math.floor(phase)+sweep(u,.015,.29))*stationAngle;
296
- const centerX=180,centerY=53,orbit=53,tableTop=33;
297
- const position=a=>[centerX+orbit*Math.cos(a),centerY+orbit*Math.sin(a)];
298
- const heads=[4,5].map(i=>position(i*stationAngle));
299
- layer("base",c=>{
300
- plinth(c,p,76,-40,213,171,5);
301
- for(const [x,y] of heads){
302
- block(c,p,x-14,y-46,5,28,18,6);
303
- block(c,p,x-9,y-41,11,18,12,84);
304
- block(c,p,x-11,y-41,83,22,51,11);
305
- poly(c,[project(x+7,y-41,90),project(x+12,y-41,100),
306
- project(x+12,y+4,100),project(x+9,y+8,93)],null,p.tone(.55),2);
716
+ }
717
+
718
+ const palletStones = [-1, 1].map(palletStone);
719
+
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);
732
+ };
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
+ }
786
+
787
+ 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");
307
797
  }
308
- cylinder(c,p,centerX,centerY,5,44,14,{top:p.top,side:p.base,end:p.base});
309
- cylinder(c,p,centerX,centerY,19,74,14,{top:p.tone(.14),side:p.end,end:p.end});
310
- planeCircle(c,centerX,centerY,tableTop,67,null,p.tone(.45),.8);
311
- });
312
- // Each workpiece and its fixture share the same angle and height.
313
- const sockets=Array.from({length:6},(_,i)=>position(angle+i*stationAngle));
314
- sockets.sort((a,b)=>a[1]-b[1]);
315
- for(const [x,y] of sockets){
316
- cylinder(c,p,x,y,tableTop,14,4,{top:p.tone(.27),side:p.end,end:p.end});
317
- cylinder(c,p,x,y,tableTop+4,10,6,{top:p.tone(.07),side:p.edge,end:p.edge});
318
- planeCircle(c,x,y,tableTop+10,6.6,p.tone(.25),p.tone(.54),.65);
319
- planeCircle(c,x,y,tableTop+10,4.7,p.ink);
320
- }
321
- cylinder(c,p,centerX,centerY,tableTop,15,5,{top:p.top,side:p.edge,end:p.edge});
322
- const indicator=angle+Math.PI*.14;
323
- for(const [lo,hi] of [[17,41],[65,72]]){
324
- const at=r=>project(centerX+r*Math.cos(indicator),centerY+r*Math.sin(indicator),tableTop+.1);
325
- poly(c,[at(lo),at(hi)],null,p.stroke,1.1);
326
- }
327
- heads.forEach(([x,y],i)=>{
328
- const offset=i*.07;
329
- const stroke=sweep(u,.39+offset,.54+offset)-sweep(u,.67+offset,.82+offset);
330
- const tip=mix(65,tableTop+10,stroke);
331
- block(c,p,x-6,y-6,67,12,12,18,{top:p.face,side:p.base,end:p.end});
332
- cylinder(c,p,x,y,tip+3,2.5,69-tip,{top:p.face,side:p.edge,end:p.edge});
333
- cylinder(c,p,x,y,tip,6,3,{top:p.top,side:p.end,end:p.end});
334
- signal(c,p,x+5,y+5,85,moving&&stroke>.85);
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
+
335
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);
834
+ }
835
+
836
+ function motionDistance(seconds) {
837
+ const ramp = 1.65, initial = 0.21, max = 1;
838
+ const t = Math.min(ramp, seconds);
839
+ return initial * t + (max - initial) * t * t / (2 * ramp) + max * (seconds - t);
336
840
  }
337
- const scenes={assembly,sorter,gantry,rotary};
841
+
842
+
843
+ const machines = {
844
+ production: (scene, distance) => singleLine(scene, distance, true),
845
+ assembly: (scene, distance) => singleLine(scene, distance, false),
846
+ sorter, gantry, rotary, clock: displayClock,
847
+ };
848
+
338
849
  globalThis.ccdxToolMachines = context => {
339
- const layers = new Map();
340
850
  let identity, colors;
341
- return (style, { time, running, reduced, width, height, dpr, ink, surface }) => {
342
- const scale = Math.min(width / 420, height / 202);
343
- const transform = [scale * dpr, 0, 0, scale * dpr, (width - 420 * scale) * dpr / 2, (height - 202 * scale) * dpr / 2];
851
+ const layers = new Map();
852
+ return (style, { time, width, height, dpr, ink, surface }) => {
853
+ const paint = machines[style];
854
+ if (!paint) return;
344
855
  const next = [style, width, height, dpr, ink, surface].join("|");
345
856
  if (identity !== next) {
346
- identity = next;layers.clear();colors = palette(ink, surface);
857
+ identity = next;
858
+ layers.clear();
859
+ colors = palette(ink, surface);
347
860
  }
348
- context.setTransform(...transform);
349
- const layer = (key, paint) => {
350
- let bitmap = layers.get(key);
351
- if (!bitmap) {
352
- bitmap = document.createElement("canvas");
353
- bitmap.width = context.canvas.width;bitmap.height = context.canvas.height;
354
- const buffer = bitmap.getContext("2d");buffer.setTransform(...transform);paint(buffer);
355
- layers.set(key, bitmap);
861
+ context.setTransform(dpr, 0, 0, dpr, 0, 0);
862
+ const scene = renderer(context, width, height, colors, style === "production" ? "line" : style);
863
+ scene.layer = (name, draw) => {
864
+ let image = layers.get(name);
865
+ if (!image) {
866
+ image = document.createElement("canvas");
867
+ image.width = context.canvas.width;
868
+ image.height = context.canvas.height;
869
+ const buffer = image.getContext("2d");
870
+ buffer.setTransform(dpr, 0, 0, dpr, 0, 0);
871
+ draw(renderer(buffer, width, height, colors, style === "production" ? "line" : style));
872
+ buffer.restore();
873
+ layers.set(name, image);
356
874
  }
357
- context.save();context.setTransform(1, 0, 0, 1, 0, 0);context.drawImage(bitmap, 0, 0);context.restore();
875
+ context.save();
876
+ context.setTransform(1, 0, 0, 1, 0, 0);
877
+ context.drawImage(image, 0, 0);
878
+ context.restore();
358
879
  };
359
- scenes[style](context, colors, time, running, reduced, layer);
880
+ paint(scene, motionDistance(Math.max(0, time)));
881
+ context.restore();
360
882
  };
361
883
  };
362
884
  })();