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.

72 lines
1.3 KiB
JavaScript

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