@thi.ng/axidraw 1.1.38 → 1.1.40
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.
- package/CHANGELOG.md +1 -1
- package/README.md +1 -1
- package/api.js +9 -19
- package/axidraw.js +376 -367
- package/commands.js +52 -88
- package/control.js +26 -31
- package/dip.js +13 -48
- package/package.json +16 -14
- package/palettes.js +68 -132
- package/polyline.js +25 -35
- package/registration.js +24 -31
- package/serial.js +31 -37
package/commands.js
CHANGED
|
@@ -1,94 +1,58 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
* @param posUp
|
|
14
|
-
*/
|
|
15
|
-
export const PEN = (posDown, posUp) => [
|
|
16
|
-
"pen",
|
|
17
|
-
posDown,
|
|
18
|
-
posUp,
|
|
1
|
+
const START = ["start"];
|
|
2
|
+
const STOP = ["stop"];
|
|
3
|
+
const HOME = ["home"];
|
|
4
|
+
const RESET = ["reset"];
|
|
5
|
+
const ON = ["on"];
|
|
6
|
+
const OFF = ["off"];
|
|
7
|
+
const SAVE = ["save"];
|
|
8
|
+
const RESTORE = ["restore"];
|
|
9
|
+
const PEN = (posDown, posUp) => [
|
|
10
|
+
"pen",
|
|
11
|
+
posDown,
|
|
12
|
+
posUp
|
|
19
13
|
];
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
* @param delay
|
|
25
|
-
* @param level
|
|
26
|
-
*/
|
|
27
|
-
export const UP = (delay, level) => [
|
|
28
|
-
"u",
|
|
29
|
-
delay,
|
|
30
|
-
level,
|
|
14
|
+
const UP = (delay, level) => [
|
|
15
|
+
"u",
|
|
16
|
+
delay,
|
|
17
|
+
level
|
|
31
18
|
];
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
* @param delay
|
|
37
|
-
* @param level
|
|
38
|
-
*/
|
|
39
|
-
export const DOWN = (delay, level) => [
|
|
40
|
-
"d",
|
|
41
|
-
delay,
|
|
42
|
-
level,
|
|
19
|
+
const DOWN = (delay, level) => [
|
|
20
|
+
"d",
|
|
21
|
+
delay,
|
|
22
|
+
level
|
|
43
23
|
];
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
* @param speed
|
|
49
|
-
*/
|
|
50
|
-
export const MOVE = (pos, speed = 1) => [
|
|
51
|
-
"M",
|
|
52
|
-
pos,
|
|
53
|
-
speed,
|
|
24
|
+
const MOVE = (pos, speed = 1) => [
|
|
25
|
+
"M",
|
|
26
|
+
pos,
|
|
27
|
+
speed
|
|
54
28
|
];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
* @param speed
|
|
60
|
-
*/
|
|
61
|
-
export const MOVE_REL = (delta, speed = 1) => [
|
|
62
|
-
"m",
|
|
63
|
-
delta,
|
|
64
|
-
speed,
|
|
29
|
+
const MOVE_REL = (delta, speed = 1) => [
|
|
30
|
+
"m",
|
|
31
|
+
delta,
|
|
32
|
+
speed
|
|
65
33
|
];
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Creates a {@link CommentCommand}.
|
|
74
|
-
*
|
|
75
|
-
* @param msg
|
|
76
|
-
*/
|
|
77
|
-
export const COMMENT = (msg) => ["comment", msg];
|
|
78
|
-
/**
|
|
79
|
-
* Syntax sugar. Takes an iterable of draw commands, adds {@link START} as
|
|
80
|
-
* prefix and {@link STOP} as suffix. I.e. it creates a "complete" drawing...
|
|
81
|
-
*
|
|
82
|
-
* @example
|
|
83
|
-
* ```ts
|
|
84
|
-
* [...complete([ MOVE([0, 0]) ])]
|
|
85
|
-
* // [ ["start"], ["M", [0, 0]], ["stop"] ]
|
|
86
|
-
* ```
|
|
87
|
-
*
|
|
88
|
-
* @param commands
|
|
89
|
-
*/
|
|
90
|
-
export function* complete(commands) {
|
|
91
|
-
yield START;
|
|
92
|
-
yield* commands;
|
|
93
|
-
yield STOP;
|
|
34
|
+
const WAIT = (delay = 1e3) => ["w", delay];
|
|
35
|
+
const COMMENT = (msg) => ["comment", msg];
|
|
36
|
+
function* complete(commands) {
|
|
37
|
+
yield START;
|
|
38
|
+
yield* commands;
|
|
39
|
+
yield STOP;
|
|
94
40
|
}
|
|
41
|
+
export {
|
|
42
|
+
COMMENT,
|
|
43
|
+
DOWN,
|
|
44
|
+
HOME,
|
|
45
|
+
MOVE,
|
|
46
|
+
MOVE_REL,
|
|
47
|
+
OFF,
|
|
48
|
+
ON,
|
|
49
|
+
PEN,
|
|
50
|
+
RESET,
|
|
51
|
+
RESTORE,
|
|
52
|
+
SAVE,
|
|
53
|
+
START,
|
|
54
|
+
STOP,
|
|
55
|
+
UP,
|
|
56
|
+
WAIT,
|
|
57
|
+
complete
|
|
58
|
+
};
|
package/control.js
CHANGED
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
import { AxiDrawState } from "./api.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
state = AxiDrawState.CONTINUE;
|
|
12
|
-
|
|
13
|
-
|
|
2
|
+
class AxiDrawControl {
|
|
3
|
+
constructor(interval = 1e3) {
|
|
4
|
+
this.interval = interval;
|
|
5
|
+
}
|
|
6
|
+
state = AxiDrawState.CONTINUE;
|
|
7
|
+
deref() {
|
|
8
|
+
return this.state;
|
|
9
|
+
}
|
|
10
|
+
reset() {
|
|
11
|
+
this.state = AxiDrawState.CONTINUE;
|
|
12
|
+
return this;
|
|
13
|
+
}
|
|
14
|
+
pause() {
|
|
15
|
+
if (this.state === AxiDrawState.CONTINUE) {
|
|
16
|
+
this.state = AxiDrawState.PAUSE;
|
|
14
17
|
}
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
this.state = AxiDrawState.CONTINUE;
|
|
20
|
-
return this;
|
|
21
|
-
}
|
|
22
|
-
pause() {
|
|
23
|
-
if (this.state === AxiDrawState.CONTINUE) {
|
|
24
|
-
this.state = AxiDrawState.PAUSE;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
resume() {
|
|
28
|
-
if (this.state === AxiDrawState.PAUSE) {
|
|
29
|
-
this.state = AxiDrawState.CONTINUE;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
cancel() {
|
|
33
|
-
this.state = AxiDrawState.CANCEL;
|
|
18
|
+
}
|
|
19
|
+
resume() {
|
|
20
|
+
if (this.state === AxiDrawState.PAUSE) {
|
|
21
|
+
this.state = AxiDrawState.CONTINUE;
|
|
34
22
|
}
|
|
23
|
+
}
|
|
24
|
+
cancel() {
|
|
25
|
+
this.state = AxiDrawState.CANCEL;
|
|
26
|
+
}
|
|
35
27
|
}
|
|
28
|
+
export {
|
|
29
|
+
AxiDrawControl
|
|
30
|
+
};
|
package/dip.js
CHANGED
|
@@ -1,52 +1,17 @@
|
|
|
1
1
|
import { flatten1 } from "@thi.ng/transducers/flatten1";
|
|
2
2
|
import { repeatedly } from "@thi.ng/transducers/repeatedly";
|
|
3
3
|
import { DOWN, RESTORE, SAVE, UP } from "./commands.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
* // [ "d", undefined ],
|
|
18
|
-
* // [ "u", undefined ],
|
|
19
|
-
* // ]
|
|
20
|
-
*
|
|
21
|
-
* // 3x dipping with custom up/down delays, each time at a random position
|
|
22
|
-
* [...DIP(3, {
|
|
23
|
-
* down: 300,
|
|
24
|
-
* up: 400,
|
|
25
|
-
* commands: () => [ MOVE([Math.random()* 5, Math.random()* 5]) ]
|
|
26
|
-
* })]
|
|
27
|
-
* // [
|
|
28
|
-
* // [ "d", 300 ],
|
|
29
|
-
* // [ "M", [ 3.996, 1.707 ], 1 ],
|
|
30
|
-
* // [ "u", 400 ],
|
|
31
|
-
* // [ "d", 300 ],
|
|
32
|
-
* // [ "M", [ 4.747, 4.925 ], 1 ],
|
|
33
|
-
* // [ "u", 400 ],
|
|
34
|
-
* // [ "d", 300 ],
|
|
35
|
-
* // [ "M", [ 1.751, 0.670 ], 1 ],
|
|
36
|
-
* // [ "u", 400 ]
|
|
37
|
-
* // ]
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* @param n
|
|
41
|
-
* @param opts
|
|
42
|
-
*/
|
|
43
|
-
export const dip = (n, opts = {}) => {
|
|
44
|
-
const down = DOWN(opts.downDelay, opts.down);
|
|
45
|
-
const up = UP(opts.upDelay, opts.up);
|
|
46
|
-
const main = flatten1(repeatedly(opts.commands
|
|
47
|
-
? () => [down, ...opts.commands(), up]
|
|
48
|
-
: () => [down, up], n));
|
|
49
|
-
return opts.down !== undefined || opts.up !== undefined
|
|
50
|
-
? [SAVE, ...main, RESTORE]
|
|
51
|
-
: main;
|
|
4
|
+
const dip = (n, opts = {}) => {
|
|
5
|
+
const down = DOWN(opts.downDelay, opts.down);
|
|
6
|
+
const up = UP(opts.upDelay, opts.up);
|
|
7
|
+
const main = flatten1(
|
|
8
|
+
repeatedly(
|
|
9
|
+
opts.commands ? () => [down, ...opts.commands(), up] : () => [down, up],
|
|
10
|
+
n
|
|
11
|
+
)
|
|
12
|
+
);
|
|
13
|
+
return opts.down !== void 0 || opts.up !== void 0 ? [SAVE, ...main, RESTORE] : main;
|
|
14
|
+
};
|
|
15
|
+
export {
|
|
16
|
+
dip
|
|
52
17
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@thi.ng/axidraw",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.40",
|
|
4
4
|
"description": "Minimal AxiDraw plotter/drawing machine controller for Node.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "./index.js",
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
"author": "Karsten Schmidt (https://thi.ng)",
|
|
25
25
|
"license": "Apache-2.0",
|
|
26
26
|
"scripts": {
|
|
27
|
-
"build": "yarn
|
|
27
|
+
"build": "yarn build:esbuild && yarn build:decl",
|
|
28
|
+
"build:decl": "tsc --declaration --emitDeclarationOnly",
|
|
29
|
+
"build:esbuild": "esbuild --format=esm --platform=neutral --target=es2022 --tsconfig=tsconfig.json --outdir=. src/**/*.ts",
|
|
28
30
|
"clean": "rimraf --glob '*.js' '*.d.ts' '*.map' doc",
|
|
29
31
|
"doc": "typedoc --excludePrivate --excludeInternal --out doc src/index.ts",
|
|
30
32
|
"doc:ae": "mkdir -p .ae/doc .ae/temp && api-extractor run --local --verbose",
|
|
@@ -33,21 +35,21 @@
|
|
|
33
35
|
"test": "bun test"
|
|
34
36
|
},
|
|
35
37
|
"dependencies": {
|
|
36
|
-
"@thi.ng/api": "^8.9.
|
|
37
|
-
"@thi.ng/checks": "^3.4.
|
|
38
|
-
"@thi.ng/compose": "^2.1.
|
|
39
|
-
"@thi.ng/date": "^2.5.
|
|
40
|
-
"@thi.ng/errors": "^2.4.
|
|
41
|
-
"@thi.ng/logger": "^2.0.
|
|
42
|
-
"@thi.ng/math": "^5.7.
|
|
43
|
-
"@thi.ng/transducers": "^8.8.
|
|
44
|
-
"@thi.ng/units": "^0.4.
|
|
45
|
-
"@thi.ng/vectors": "^7.8.
|
|
38
|
+
"@thi.ng/api": "^8.9.12",
|
|
39
|
+
"@thi.ng/checks": "^3.4.12",
|
|
40
|
+
"@thi.ng/compose": "^2.1.51",
|
|
41
|
+
"@thi.ng/date": "^2.5.6",
|
|
42
|
+
"@thi.ng/errors": "^2.4.6",
|
|
43
|
+
"@thi.ng/logger": "^2.0.2",
|
|
44
|
+
"@thi.ng/math": "^5.7.7",
|
|
45
|
+
"@thi.ng/transducers": "^8.8.15",
|
|
46
|
+
"@thi.ng/units": "^0.4.19",
|
|
47
|
+
"@thi.ng/vectors": "^7.8.9",
|
|
46
48
|
"serialport": "^12.0.0"
|
|
47
49
|
},
|
|
48
50
|
"devDependencies": {
|
|
49
51
|
"@microsoft/api-extractor": "^7.38.3",
|
|
50
|
-
"
|
|
52
|
+
"esbuild": "^0.19.8",
|
|
51
53
|
"rimraf": "^5.0.5",
|
|
52
54
|
"tools": "^0.0.1",
|
|
53
55
|
"typedoc": "^0.25.4",
|
|
@@ -114,5 +116,5 @@
|
|
|
114
116
|
"status": "alpha",
|
|
115
117
|
"year": 2022
|
|
116
118
|
},
|
|
117
|
-
"gitHead": "
|
|
119
|
+
"gitHead": "5e7bafedfc3d53bc131469a28de31dd8e5b4a3ff\n"
|
|
118
120
|
}
|
package/palettes.js
CHANGED
|
@@ -7,139 +7,75 @@ import { madd2 } from "@thi.ng/vectors/madd";
|
|
|
7
7
|
import { maddN2 } from "@thi.ng/vectors/maddn";
|
|
8
8
|
import { MOVE } from "./commands.js";
|
|
9
9
|
import { dip } from "./dip.js";
|
|
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
|
-
* // configure palette
|
|
35
|
-
* const palette = linearPalette({
|
|
36
|
-
* // first palette slot is near the world origin (slight offset)
|
|
37
|
-
* pos: [2, 0],
|
|
38
|
-
* // palette has 5 paint slots
|
|
39
|
-
* num: 5,
|
|
40
|
-
* // each slot 40mm separation along Y-axis
|
|
41
|
-
* // (needs to be measured/determined manually)
|
|
42
|
-
* step: [0, 40],
|
|
43
|
-
* // 2mm jitter radius (to not always move to exact same position)
|
|
44
|
-
* jitter: 2,
|
|
45
|
-
* // dip brush 3x each time
|
|
46
|
-
* repeat: 3,
|
|
47
|
-
* });
|
|
48
|
-
*
|
|
49
|
-
* // investigate command sequence for requesting slot #1
|
|
50
|
-
* palette(1)
|
|
51
|
-
* // [
|
|
52
|
-
* // [ "M", [ 0.8949, 41.6697 ], 1 ],
|
|
53
|
-
* // [ "d", undefined, undefined ],
|
|
54
|
-
* // [ "u", undefined, undefined ],
|
|
55
|
-
* // [ "d", undefined, undefined ],
|
|
56
|
-
* // [ "u", undefined, undefined ],
|
|
57
|
-
* // [ "d", undefined, undefined ],
|
|
58
|
-
* // [ "u", undefined, undefined ]
|
|
59
|
-
* // ]
|
|
60
|
-
*
|
|
61
|
-
* // define point cloud of 100 random points
|
|
62
|
-
* // using a random palette slot each time (for each refill)
|
|
63
|
-
* // assign axidraw-specific attribs to refill brush every 10 dots
|
|
64
|
-
* const cloud = points(
|
|
65
|
-
* [...repeatedly(() => randMinMax2([], [10, 10], [190, 190]), 100)],
|
|
66
|
-
* {
|
|
67
|
-
* __axi: {
|
|
68
|
-
* interleave: {
|
|
69
|
-
* num: 10,
|
|
70
|
-
* commands: () => palette((Math.random() * 5) | 0)
|
|
71
|
-
* }
|
|
72
|
-
* }
|
|
73
|
-
* }
|
|
74
|
-
* );
|
|
75
|
-
*
|
|
76
|
-
* // AxiDraw setup
|
|
77
|
-
* const axi = new AxiDraw();
|
|
78
|
-
* ...
|
|
79
|
-
*
|
|
80
|
-
* // convert geometry into axidraw commands and send to plotter
|
|
81
|
-
* axi.draw(asAxiDraw(cloud));
|
|
82
|
-
* ```
|
|
83
|
-
*
|
|
84
|
-
* @param opts
|
|
85
|
-
*/
|
|
86
|
-
export const linearPalette = (opts) => {
|
|
87
|
-
const $opts = {
|
|
88
|
-
pos: [0, 0],
|
|
89
|
-
repeat: 1,
|
|
90
|
-
jitter: 0,
|
|
91
|
-
...opts,
|
|
92
|
-
};
|
|
93
|
-
const dipOpts = __dipOpts($opts);
|
|
94
|
-
return (id) => {
|
|
95
|
-
if (id < 0 || id >= $opts.num) {
|
|
96
|
-
illegalArgs(`invalid palette index: ${id}`);
|
|
97
|
-
}
|
|
98
|
-
return [
|
|
99
|
-
MOVE(jitter(null, maddN2([], $opts.step, id, $opts.pos), $opts.jitter)),
|
|
100
|
-
...dip($opts.repeat, dipOpts),
|
|
101
|
-
];
|
|
102
|
-
};
|
|
10
|
+
const linearPalette = (opts) => {
|
|
11
|
+
const $opts = {
|
|
12
|
+
pos: [0, 0],
|
|
13
|
+
repeat: 1,
|
|
14
|
+
jitter: 0,
|
|
15
|
+
...opts
|
|
16
|
+
};
|
|
17
|
+
const dipOpts = __dipOpts($opts);
|
|
18
|
+
return (id) => {
|
|
19
|
+
if (id < 0 || id >= $opts.num) {
|
|
20
|
+
illegalArgs(`invalid palette index: ${id}`);
|
|
21
|
+
}
|
|
22
|
+
return [
|
|
23
|
+
MOVE(
|
|
24
|
+
jitter(
|
|
25
|
+
null,
|
|
26
|
+
maddN2([], $opts.step, id, $opts.pos),
|
|
27
|
+
$opts.jitter
|
|
28
|
+
)
|
|
29
|
+
),
|
|
30
|
+
...dip($opts.repeat, dipOpts)
|
|
31
|
+
];
|
|
32
|
+
};
|
|
103
33
|
};
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
*
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
jitter
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
34
|
+
const radialPalette = (opts) => {
|
|
35
|
+
const $opts = {
|
|
36
|
+
repeat: 1,
|
|
37
|
+
jitter: 0,
|
|
38
|
+
startTheta: 0,
|
|
39
|
+
endTheta: Math.PI * 2,
|
|
40
|
+
...opts
|
|
41
|
+
};
|
|
42
|
+
const radius = isNumber($opts.radius) ? [$opts.radius, $opts.radius] : $opts.radius;
|
|
43
|
+
const dipOpts = __dipOpts($opts);
|
|
44
|
+
return (id) => {
|
|
45
|
+
if (id < 0 || id >= $opts.num) {
|
|
46
|
+
illegalArgs(`invalid palette index: ${id}`);
|
|
47
|
+
}
|
|
48
|
+
return [
|
|
49
|
+
MOVE(
|
|
50
|
+
jitter(
|
|
51
|
+
null,
|
|
52
|
+
madd2(
|
|
53
|
+
null,
|
|
54
|
+
cossin(
|
|
55
|
+
mix(
|
|
56
|
+
$opts.startTheta,
|
|
57
|
+
$opts.endTheta,
|
|
58
|
+
id / $opts.num
|
|
59
|
+
)
|
|
60
|
+
),
|
|
61
|
+
radius,
|
|
62
|
+
$opts.pos
|
|
63
|
+
),
|
|
64
|
+
$opts.jitter
|
|
65
|
+
)
|
|
66
|
+
),
|
|
67
|
+
...dip($opts.repeat, dipOpts)
|
|
68
|
+
];
|
|
69
|
+
};
|
|
138
70
|
};
|
|
139
71
|
const __dipOpts = (opts) => ({
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
72
|
+
down: opts.down,
|
|
73
|
+
downDelay: opts.downDelay,
|
|
74
|
+
up: opts.up,
|
|
75
|
+
upDelay: opts.upDelay,
|
|
76
|
+
commands: opts.commands
|
|
145
77
|
});
|
|
78
|
+
export {
|
|
79
|
+
linearPalette,
|
|
80
|
+
radialPalette
|
|
81
|
+
};
|
package/polyline.js
CHANGED
|
@@ -1,37 +1,27 @@
|
|
|
1
1
|
import { DOWN, MOVE, PEN, UP } from "./commands.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
yield MOVE(p, speed);
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
|
-
yield MOVE(pts[0]);
|
|
28
|
-
if (down !== undefined)
|
|
29
|
-
yield PEN(down);
|
|
30
|
-
yield DOWN(delayDown);
|
|
31
|
-
for (let i = 1, n = pts.length; i < n; i++)
|
|
32
|
-
yield MOVE(pts[i], speed);
|
|
33
|
-
yield UP(delayUp);
|
|
34
|
-
// reset pen to configured defaults
|
|
35
|
-
if (down !== undefined)
|
|
36
|
-
yield PEN();
|
|
2
|
+
function* polyline(pts, opts) {
|
|
3
|
+
if (!pts.length)
|
|
4
|
+
return;
|
|
5
|
+
const { speed, delayDown, delayUp, down, onlyGeo } = {
|
|
6
|
+
speed: 1,
|
|
7
|
+
onlyGeo: false,
|
|
8
|
+
...opts
|
|
9
|
+
};
|
|
10
|
+
if (onlyGeo) {
|
|
11
|
+
for (let p of pts)
|
|
12
|
+
yield MOVE(p, speed);
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
yield MOVE(pts[0]);
|
|
16
|
+
if (down !== void 0)
|
|
17
|
+
yield PEN(down);
|
|
18
|
+
yield DOWN(delayDown);
|
|
19
|
+
for (let i = 1, n = pts.length; i < n; i++)
|
|
20
|
+
yield MOVE(pts[i], speed);
|
|
21
|
+
yield UP(delayUp);
|
|
22
|
+
if (down !== void 0)
|
|
23
|
+
yield PEN();
|
|
37
24
|
}
|
|
25
|
+
export {
|
|
26
|
+
polyline
|
|
27
|
+
};
|
package/registration.js
CHANGED
|
@@ -2,35 +2,28 @@ import { map } from "@thi.ng/transducers/map";
|
|
|
2
2
|
import { normRange } from "@thi.ng/transducers/norm-range";
|
|
3
3
|
import { cartesian2 } from "@thi.ng/vectors/cartesian";
|
|
4
4
|
import { DOWN, MOVE, UP } from "./commands.js";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
MOVE([
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
MOVE([x, y - size]),
|
|
27
|
-
DOWN(),
|
|
28
|
-
MOVE([x, y + size]),
|
|
29
|
-
UP(),
|
|
30
|
-
// circle
|
|
31
|
-
MOVE([x + r, y]),
|
|
32
|
-
DOWN(),
|
|
33
|
-
...map((t) => MOVE(cartesian2([], [r, t * Math.PI * 2], [x, y])), normRange(40)),
|
|
34
|
-
UP(),
|
|
35
|
-
MOVE([x, y]),
|
|
5
|
+
const registrationMark = ([x, y], size = 5, r = size * 0.75) => [
|
|
6
|
+
// crosshair
|
|
7
|
+
// horizontal
|
|
8
|
+
MOVE([x - size, y]),
|
|
9
|
+
DOWN(),
|
|
10
|
+
MOVE([x + size, y]),
|
|
11
|
+
UP(),
|
|
12
|
+
// vertical
|
|
13
|
+
MOVE([x, y - size]),
|
|
14
|
+
DOWN(),
|
|
15
|
+
MOVE([x, y + size]),
|
|
16
|
+
UP(),
|
|
17
|
+
// circle
|
|
18
|
+
MOVE([x + r, y]),
|
|
19
|
+
DOWN(),
|
|
20
|
+
...map(
|
|
21
|
+
(t) => MOVE(cartesian2([], [r, t * Math.PI * 2], [x, y])),
|
|
22
|
+
normRange(40)
|
|
23
|
+
),
|
|
24
|
+
UP(),
|
|
25
|
+
MOVE([x, y])
|
|
36
26
|
];
|
|
27
|
+
export {
|
|
28
|
+
registrationMark
|
|
29
|
+
};
|