You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

73 lines
1.4 KiB
JavaScript

11 months ago
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}`)
11 months ago
if (state.position.x > 100) {
console.log("in the borderland up");
11 months ago
state.position.x = 100;
} else if (state.position.x < 0) {
console.log("in the borderland down");
11 months ago
state.position.x = 0;
}
if (state.position.y > 100) {
console.log("in the borderland up");
11 months ago
state.position.y = 100;
} else if (state.position.y < 0) {
console.log("in the borderland down");
11 months ago
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
}