diff --git a/app.js b/app.js index 30aae22..d6bd923 100644 --- a/app.js +++ b/app.js @@ -70,7 +70,7 @@ const parseMessage = (message) => { } else { switch (message.toLowerCase()) { case 'init': - toPlotter(translate()); + toPlotter(init()); break; case 'pu': toPlotter(`PU;`); @@ -79,7 +79,7 @@ const parseMessage = (message) => { toPlotter(`PD;`); break; case 'up': - toPlotter(translate(distance * -1, 0)); + toPlotter(translate(0, distance * -1)); break; case 'down': toPlotter(translate(0, distance)); @@ -88,10 +88,7 @@ const parseMessage = (message) => { toPlotter(translate(distance * -1, 0)); break; case 'right': - toPlotter(translate(0, distance)); - break; - case 'right': - toPlotter(translate(0, distance)); + toPlotter(translate(distance, 0)); break; case 'rectangle': toPlotter(rectangle(distance)); diff --git a/hpgl.js b/hpgl.js index 4d2b377..1fac2fd 100644 --- a/hpgl.js +++ b/hpgl.js @@ -10,12 +10,15 @@ function init(width = 4000, height = 4000) { } 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 `PR${state.position.x},${state.position.y};` + return `PA${state.position.x},${state.position.y};` } function to(x = 0, y = 0) {