Skip to content

Commit

Permalink
Bug Fix: towards and distance
Browse files Browse the repository at this point in the history
both towards and distance should optionally take a turtle as a parameter rather than two numbers.
  • Loading branch information
bnmnetp committed Feb 14, 2013
1 parent 6c609de commit fae67e3
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/lib/turtle/__init__.js
Original file line number Diff line number Diff line change
Expand Up @@ -1462,16 +1462,22 @@ var $builtinmodule = function(name) {
});

$loc.towards = new Sk.builtin.func(function(self, tx, ty) {
if ((typeof(tx)).toLowerCase() === 'number')
if ((typeof(tx)).toLowerCase() === 'number') {
tx = [tx, ty, 0];
} else {
tx = [tx.theTurtle.getx(),tx.theTurtle.gety(),0]
}
return self.theTurtle.towards(tx);
});

// tx can be either a number or a vector position.
// tx can not be a turtle at this time as multiple turtles have not been implemented yet.
$loc.distance = new Sk.builtin.func(function(self, tx, ty) {
if ((typeof(tx)).toLowerCase() === 'number')
if ((typeof(tx)).toLowerCase() === 'number') {
tx = [tx, ty, 0];
} else {
tx = [self.theTurtle.getx(), self.theTurtle.gety(), 0];
}
return self.theTurtle.distance(tx);
});

Expand Down

0 comments on commit fae67e3

Please sign in to comment.