Clean up degrees vs radians.
Chris Pressey
2 years ago
186 | 186 |
turtle.moveBy(instr[1]);
|
187 | 187 |
break;
|
188 | 188 |
case "rt":
|
189 | |
turtle.rotateByDeg(instr[1]);
|
|
189 |
turtle.rotateBy(instr[1]);
|
190 | 190 |
break;
|
191 | 191 |
case "lt":
|
192 | |
turtle.rotateByDeg(-1 * instr[1]);
|
|
192 |
turtle.rotateBy(-1 * instr[1]);
|
193 | 193 |
break;
|
194 | 194 |
case "setxyp":
|
195 | 195 |
turtle.setXYProportional(instr[1], instr[2]);
|
21 | 21 |
this.moveError = 0.0;
|
22 | 22 |
};
|
23 | 23 |
|
24 | |
/* theta is in radians */
|
|
24 |
/* theta is in degrees */
|
25 | 25 |
this.setTheta = function(theta) {
|
26 | 26 |
this.theta = theta;
|
27 | 27 |
this.dx = Math.cos(theta);
|
28 | 28 |
this.dy = Math.sin(theta);
|
29 | |
};
|
30 | |
|
31 | |
this.setThetaDeg = function(theta) {
|
32 | |
this.setTheta(theta * DEG);
|
33 | 29 |
};
|
34 | 30 |
|
35 | 31 |
this.setXYProportional = function(xp, yp) {
|
|
52 | 48 |
this.moveError += dmerr;
|
53 | 49 |
};
|
54 | 50 |
|
55 | |
/* dtheta is in radians */
|
|
51 |
/* dtheta is in degrees */
|
56 | 52 |
this.rotateBy = function(dtheta) {
|
57 | 53 |
var error = (Math.random() - 0.5) * this.rotateError;
|
58 | |
this.setTheta(this.theta + dtheta + error);
|
59 | |
};
|
60 | |
|
61 | |
this.rotateByDeg = function(dtheta) {
|
62 | |
this.rotateBy(dtheta * DEG);
|
|
54 |
this.setTheta(this.theta + (dtheta * DEG) + error);
|
63 | 55 |
};
|
64 | 56 |
|
65 | 57 |
this.moveBy = function(units) {
|