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.

76 lines
1.5 KiB
JavaScript

const state = {
position: {
x: 0,
y: 0
}
}
function init(width = 1188000, height = 168000) {
return `IN;IP0,0,${width},${height};SC0,100,0,100;SP1; `
}
function translate(x = 0, y = 0) {
console.log(`translate: ${x} ${y}`);
state.position.x += x;
state.position.y += y;
console.log(`translate: ${state.position.x}`);
clampPosition();
return `PA${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
}