diff --git a/assets/tests.json b/assets/tests.json index a8857d6..b4c3e77 100644 --- a/assets/tests.json +++ b/assets/tests.json @@ -13,6 +13,13 @@ "width": 200, "height": 200 }, + { + "name": "Pensize Test", + "code": "fd 40 rt 90 color 556699 pensize 5 fd 40 color 334433 pensize 1 lt -90 fd 40 pensize 5 color 556699 rt 90 fd 40", + "author": "https://github.com/toyz", + "width": 200, + "height": 200 + }, { "name": "Coding Train Logo", "code": "rt -2 fd 44 rt 70 fd 15 rt 35 fd 17 rt 76 fd 47 rt 92 fd 63 rt -94 fd 55 rt -120 fd 5 rt 26 fd 40 rt 30 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -23 fd 10 rt -20 fd 5 pu rt 142 fd 38 pd rt 85 fd 38 rt 94 fd 30 rt 106 fd 10 rt -10 fd 10 rt -15 fd 13 rt 88 fd 26 pu rt 85 fd 34 pd rt -80 fd 5 rt 70 fd 7 rt 110 fd 7 pu rt -15 fd 36 pd rt -170 fd 8 rt 95 fd 7 rt 95 fd 7 pu rt 22 fd 51 pd rt -118 fd 4 lt 40 fd 4 rt 25 fd 4 rt 25 fd 4 rt 25 fd 4 lt 30 fd 4 lt 25 fd 4 rt 25 fd 4 rt 25 fd 5 lt 25 fd 5 rt 60 fd 8 lt 60 fd 20 lt 117 fd 22 pu lt 63 fd 20 pd lt 115 fd 14 rt 90 fd 3 lt 60 fd 3 rt 25 fd 3 rt 25 fd 3 rt 25 fd 3 rt 25 fd 3 rt 25 fd 3 rt 140 fd 6 lt 90 fd 5 lt 90 fd 20 lt 90 fd 5 lt 90 fd 20 lt 180 fd 12 lt 50 fd 2 rt 25 fd 3 rt 25 fd 3 rt 25 fd 3 rt 25 fd 3 rt 25 fd 3 pu lt 24 fd 32 pd lt 35 fd 5 lt 35 fd 5 lt 35 fd 5 lt 35 fd 5 lt 35 fd 5 lt 35 fd 5 lt 35 fd 5 lt 35 fd 5 lt 35 fd 5 lt 35 fd 5 pu rt 97 fd 45 pd rt 110 fd 19 pu lt 90 fd 5 pd lt 90 fd 19 pu rt 90 fd 5 pd rt 90 fd 19 pu lt 90 fd 6 pd lt 90 fd 19 pu rt 25 fd 7 pd lt 15 fd 25 lt 100 fd 26 lt 95 fd 25 rt 180 fd 25 lt 90 fd 3 rt 85 fd 8 rt 100 fd 35 rt 110 fd 8 pu rt 20 fd 95 pd rt 100 fd 15 pu rt 66 fd 6 pd rt 75 fd 16 pu lt 110 fd 20 pd lt 115 fd 15 pu rt 50 fd 6 pd rt 90 fd 17 pu lt 115 fd 20 pd lt 115 fd 17 pu rt 72 fd 6 pd rt 70 fd 17 pu lt 124 fd 23 pd lt 118 fd 17 pu rt 72 fd 6 pd rt 70 fd 15 pu lt 158 fd 95 pd lt 30 fd 5 lt 20 fd 5 lt 20 fd 5 lt 20 fd 10 lt 20 fd 10 lt 20 fd 10 pu lt 146 fd 45 pd lt 110 fd 10 lt 20 fd 5 lt 15 fd 5 lt 15 fd 5 lt 15 fd 10 lt 15 fd 10 lt 15 fd 15 pu lt 150 fd 60 pd lt 120 fd 10 lt 20 fd 12 lt 15 fd 10 lt 15 fd 5 lt 10 fd 12 lt 17 fd 12 lt 15 fd 20 pu lt 145 fd 80 pd lt 120 fd 15 lt 20 fd 15 lt 15 fd 15 lt 15 fd 5 lt 10 fd 12 lt 17 fd 15 lt 15 fd 27 rt 40 fd 5 lt 25 fd 10 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 180 fd 5 lt 60 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 180 fd 5 lt 60 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 180 fd 5 lt 60 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 25 fd 5 lt 180 fd 5 lt 50 fd 5 lt 25 fd 3 lt 50 fd 5 lt 20 fd 5 lt 30 fd 5 lt 30 fd 3 lt 180 fd 6 lt 40 fd 6 lt 40 fd 5", diff --git a/command.js b/command.js index 6683cd8..dcc40a1 100644 --- a/command.js +++ b/command.js @@ -77,7 +77,7 @@ class CommandExecutor { * @memberof CommandExecutor */ constructor(command, values, callback) { - this.callback = callback + this.callback = callback; this.command = command; this.values = []; @@ -96,9 +96,7 @@ class CommandExecutor { this.values.push(value); break; case COMMAND_TYPES.COMMANDS: - this.values.push( - new Parser(value, this.callback).parse() - ); + this.values.push(new Parser(value, this.callback).parse()); break; case COMMAND_TYPES.PARAMETERS: // Example this.values.push(value.split(" ")); @@ -144,7 +142,7 @@ class CommandLookUp { /** * Creates an instance of CommandLookUp. - * @memberof CommandLookUp + * @memberokUp */ constructor() { this.commands = []; diff --git a/commandList.js b/commandList.js index f76837f..186be84 100644 --- a/commandList.js +++ b/commandList.js @@ -44,6 +44,16 @@ commandLookUp.add( }) ); +commandLookUp.add( + new Command( + "pensize", + [new CommandArg("size", COMMAND_TYPES.FLOAT)], + size => { + turtle.strokeWeight = size; + } + ) +); + commandLookUp.add( new Command( "setxy", @@ -78,13 +88,13 @@ commandLookUp.add( commandLookUp.add( new Command("radians", [], () => { - angleMode(DEGREES); + angleMode(RADIANS); }) ); commandLookUp.add( new Command("degrees", [], () => { - angleMode(RADIANS); + angleMode(DEGREES); }) ); diff --git a/sketch.js b/sketch.js index cc7562a..18a74ea 100644 --- a/sketch.js +++ b/sketch.js @@ -100,6 +100,7 @@ function createTestDataView(cases) { turtle.dir = 0; turtle.x = width / 2; turtle.y = height / 2; + editor.value(""); // Empty this on "-1" select return; } diff --git a/turtle.js b/turtle.js index 31d43f4..9238c94 100644 --- a/turtle.js +++ b/turtle.js @@ -7,6 +7,7 @@ class Turtle { this.dir = angle; this.strokeColor = 255; + this.strokeWeight = 1; } reset() { @@ -17,10 +18,9 @@ class Turtle { } forward(amt) { - amt = parseInt(amt); if (this.pen) { stroke(this.strokeColor); - strokeWeight(1); + strokeWeight(this.strokeWeight); line(0, 0, amt, 0); } translate(amt, 0);