|
|
|
const state = {
|
|
|
|
position: {
|
|
|
|
x: 0,
|
|
|
|
y: 0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function init(width = 4000, height = 4000) {
|
|
|
|
return `IN;IP0,0,${width},${height};SC0,100,0,100;SP1; `
|
|
|
|
}
|
|
|
|
|
|
|
|
function translate(x = 0, y = 0) {
|
|
|
|
state.position.x += x;
|
|
|
|
state.position.y += y;
|
|
|
|
|
|
|
|
clampPosition();
|
|
|
|
|
|
|
|
return `PR${state.position.x},${state.position.y};`
|
|
|
|
}
|
|
|
|
|
|
|
|
function to(x = 0, y = 0) {
|
|
|
|
state.position.x = x;
|
|
|
|
state.position.y = y;
|
|
|
|
|
|
|
|
clampPosition();
|
|
|
|
|
|
|
|
return `PA${state.position.x},${state.position.y};`
|
|
|
|
}
|
|
|
|
|
|
|
|
function circle(radius, resolution = 10) {
|
|
|
|
return `CT${resolution};PA${state.position.x},${state.position.y};PD;CI${radius};PU;`
|
|
|
|
}
|
|
|
|
|
|
|
|
function clampPosition() {
|
|
|
|
console.log(`clampPosition: ${state.position.x} ${state.position.y}`)
|
|
|
|
if (state.position.x > 100) {
|
|
|
|
console.log("in the borderland up");
|
|
|
|
state.position.x = 100;
|
|
|
|
} else if (state.position.x < 0) {
|
|
|
|
console.log("in the borderland down");
|
|
|
|
state.position.x = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (state.position.y > 100) {
|
|
|
|
console.log("in the borderland up");
|
|
|
|
state.position.y = 100;
|
|
|
|
} else if (state.position.y < 0) {
|
|
|
|
console.log("in the borderland down");
|
|
|
|
state.position.y = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function rectangle(width, height) {
|
|
|
|
if (!height) {
|
|
|
|
height = width;
|
|
|
|
}
|
|
|
|
|
|
|
|
return `PD;FT1;RR${width},${height};`
|
|
|
|
}
|
|
|
|
|
|
|
|
function label(string) {
|
|
|
|
return `DT$,0;SI0.5,0.8;LB${string}$;`;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = {
|
|
|
|
init,
|
|
|
|
translate,
|
|
|
|
circle,
|
|
|
|
rectangle,
|
|
|
|
to,
|
|
|
|
label
|
|
|
|
}
|