Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added pensize and test for it #48

Merged
merged 10 commits into from
Nov 12, 2018
7 changes: 7 additions & 0 deletions assets/tests.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 3 additions & 5 deletions command.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ class CommandExecutor {
* @memberof CommandExecutor
*/
constructor(command, values, callback) {
this.callback = callback
this.callback = callback;
this.command = command;
this.values = [];

Expand All @@ -95,9 +95,7 @@ class CommandExecutor {
case COMMAND_TYPES.FLOAT:
this.values.push(parseFloat(value));
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(" "));
Expand Down Expand Up @@ -132,7 +130,7 @@ class CommandLookUp {

/**
* Creates an instance of CommandLookUp.
* @memberof CommandLookUp
* @memberokUp
*/
constructor() {
this.commands = [];
Expand Down
14 changes: 12 additions & 2 deletions commandList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -78,13 +88,13 @@ commandLookUp.add(

commandLookUp.add(
new Command("radians", [], () => {
angleMode(DEGREES);
angleMode(RADIANS);
})
);

commandLookUp.add(
new Command("degrees", [], () => {
angleMode(RADIANS);
angleMode(DEGREES);
})
);

Expand Down
26 changes: 0 additions & 26 deletions parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,32 +78,6 @@ class Parser {
parse() {
let cmdsExecutors = [];
while (this.remainingTokens()) {
let token = this.nextToken();
let cmd = undefined;

// testCommand to refactor
function testCommand(value, data) { return value.test(data) }

if (testCommand(movement, token)) {
cmd = new Command(token, parseFloat(this.nextToken()));
} else if (testCommand(noArgsCalls, token)) {
cmd = new Command(token);
} else if (testCommand(repeat, token)) {
cmd = new Command(token, parseInt(this.nextToken()));
let toRepeat = this.getRepeat();
let parser = new Parser(toRepeat);
cmd.commands = parser.parse();
} else if (testCommand(setxy,token)) {
cmd = new Command(token);
let argX = this.nextToken();
let argY = this.nextToken();
cmd.arg = [parseFloat(argX), parseFloat(argY)];
} else if (testCommand(color, token)) {
cmd = new Command(token, this.nextToken());
} else if (testCommand(setxySingle,token)) {
cmd = new Command(token, parseFloat(this.nextToken()));
}

const actualToken = this.nextToken();
let cmd = commandLookUp.get(actualToken);

Expand Down
1 change: 1 addition & 0 deletions sketch.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
4 changes: 2 additions & 2 deletions turtle.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class Turtle {

this.dir = angle;
this.strokeColor = 255;
this.strokeWeight = 1;
}

reset() {
Expand All @@ -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);
Expand Down