Skip to content

Commit

Permalink
Remove getValue function
Browse files Browse the repository at this point in the history
  • Loading branch information
takluyver committed Jun 14, 2014
1 parent 7f7fd35 commit f4b6d2f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 70 deletions.
8 changes: 4 additions & 4 deletions Test.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:9b224554c4c626bd17e8b734b4a439b7b682cc4985edb83e2fb0cc63fe60e3e7"
"signature": "sha256:2a19e89154b1b863d5766996f56c53701652c2eb96c8a0dfa5cb49bd8d8a827f"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand All @@ -14,7 +14,7 @@
"input": [
"from NewTurtle import Turtle\n",
"t = Turtle();\n",
"t.speed(10)\n",
"t.speed(1)\n",
"colours=[\"red\",\"blue\",\"yellow\",\"brown\",\"black\",\"purple\",\"green\"]\n",
"t.penup(); t.left(90); t.forward(200);t.right(90);t.pendown();\n",
"for i in range (0,18):\n",
Expand All @@ -27,13 +27,13 @@
"outputs": [
{
"javascript": [
"IPython.do_turtle(\"1,black,200,200,0,1,0,black,200,200,-90,10,0,black,200.0,20,0,10,0,black,200.0,20,90,10,1,red,200.0,20,20,10,1,red,247.0,37.1,0,10,1,blue,247.0,37.1,20,10,1,blue,285.3,69.2,0,10,1,yellow,285.3,69.2,20,10,1,yellow,310.3,112.5,0,10,1,brown,310.3,112.5,20,10,1,brown,319.0,161.7,0,10,1,black,319.0,161.7,20,10,1,black,310.3,210.89999999999998,0,10,1,purple,310.3,210.89999999999998,20,10,1,purple,285.3,254.2,0,10,1,green,285.3,254.2,20,10,1,green,247.0,286.3,0,10,1,red,247.0,286.3,20,10,1,red,200.0,303.40000000000003,0,10,1,blue,200.0,303.40000000000003,20,10,1,blue,150.0,303.40000000000003,0,10,1,yellow,150.0,303.40000000000003,20,10,1,yellow,103.0,286.3,0,10,1,brown,103.0,286.3,20,10,1,brown,64.7,254.20000000000002,0,10,1,black,64.7,254.20000000000002,20,10,1,black,39.7,210.90000000000003,0,10,1,purple,39.7,210.90000000000003,20,10,1,purple,31.000000000000004,161.70000000000005,0,10,1,green,31.000000000000004,161.70000000000005,20,10,1,green,39.7,112.50000000000004,0,10,1,red,39.7,112.50000000000004,20,10,1,red,64.7,69.20000000000005,0,10,1,blue,64.7,69.20000000000005,20,10,1,blue,103.0,37.100000000000044,0,10,1,yellow,103.0,37.100000000000044,20,10,1,yellow,150.0,20.000000000000043,0,10,1,brown,150.0,20.000000000000043,20,10,1,brown,200.0,20.000000000000043,0,10,\", element);"
"IPython.do_turtle(\"1,black,200,200,0,1,0,black,200,200,-90,1,0,black,200.0,20,0,1,0,black,200.0,20,90,1,1,red,200.0,20,20,1,1,red,247.0,37.1,0,1,1,blue,247.0,37.1,20,1,1,blue,285.3,69.2,0,1,1,yellow,285.3,69.2,20,1,1,yellow,310.3,112.5,0,1,1,brown,310.3,112.5,20,1,1,brown,319.0,161.7,0,1,1,black,319.0,161.7,20,1,1,black,310.3,210.89999999999998,0,1,1,purple,310.3,210.89999999999998,20,1,1,purple,285.3,254.2,0,1,1,green,285.3,254.2,20,1,1,green,247.0,286.3,0,1,1,red,247.0,286.3,20,1,1,red,200.0,303.40000000000003,0,1,1,blue,200.0,303.40000000000003,20,1,1,blue,150.0,303.40000000000003,0,1,1,yellow,150.0,303.40000000000003,20,1,1,yellow,103.0,286.3,0,1,1,brown,103.0,286.3,20,1,1,brown,64.7,254.20000000000002,0,1,1,black,64.7,254.20000000000002,20,1,1,black,39.7,210.90000000000003,0,1,1,purple,39.7,210.90000000000003,20,1,1,purple,31.000000000000004,161.70000000000005,0,1,1,green,31.000000000000004,161.70000000000005,20,1,1,green,39.7,112.50000000000004,0,1,1,red,39.7,112.50000000000004,20,1,1,red,64.7,69.20000000000005,0,1,1,blue,64.7,69.20000000000005,20,1,1,blue,103.0,37.100000000000044,0,1,1,yellow,103.0,37.100000000000044,20,1,1,yellow,150.0,20.000000000000043,0,1,1,brown,150.0,20.000000000000043,20,1,1,brown,200.0,20.000000000000043,0,1,\", element);"
],
"metadata": {},
"output_type": "display_data"
}
],
"prompt_number": 11
"prompt_number": 19
},
{
"cell_type": "code",
Expand Down
83 changes: 17 additions & 66 deletions static/myScript.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,55 +116,6 @@ function TurtleDrawing(data, canvas_element, grid_button, help_button) {
}
};
this.parse_points();

/*
getValue splits up the string with any turtle infromation, breaks it up
into points which have an x, y and b value. It is called 6 times for every turtle command entered (once for each new and old point value). Count is itterated for
turtle command entered. The count argument should tell the function which turtle
command you want information about, the coord argument should specify which or the 6 possible pieces of information about each command you're looking for.
*/
TurtleDrawing.prototype.getValue = function (count,coord){
var wCoord = coord;
var wCount = count;
var points = this.points;

if(coord == 1){
return oldPen = points[wCount].p;
}
else if(coord == 2){
return oldColour = points[wCount].lc;
}
else if(coord == 3){
return oldX = points[wCount].x;
}
else if(coord == 4){
return oldY = points[wCount].y;
}
else if(coord == 5){
return oldRotation = points[wCount].b;
}
else if(coord == 6){
return turtleSpeed = points[wCount].s;
}
else if(coord == 7){
return newPen = points[wCount+1].p;
}
else if(coord == 8){
return newColour = points[wCount+1].lc;
}
else if(coord == 9){
return newX = points[wCount+1].x;
}
else if(coord == 10){
return newY = points[wCount+1].y;
}
else if(coord == 11){
return newRotation = points[wCount+1].b;
}
else if(coord == 12){
return turtleSpeed = points[wCount+1].s;
}
}

// some variable to play with still
this.lineSize = 2;
Expand Down Expand Up @@ -201,28 +152,28 @@ function TurtleDrawing(data, canvas_element, grid_button, help_button) {
*/
TurtleDrawing.prototype.nextCount = function (){
var count = this.count;
this.oldPen = this.getValue(count, 1);
this.oldColour = this.getValue(count, 2);
this.oldX = this.getValue(count,3);
this.oldY = this.getValue(count,4);
this.oldRotation = this.getValue(count,5);
this.turtleSpeed = this.getValue(count,6);
this.newPen = this.getValue(count, 7);
this.newColour = this.getValue(count, 8);
this.newX = this.getValue(count,9);
this.newY = this.getValue(count,10);
this.changRot = this.getValue(count,11);
this.turtleSpeed = this.getValue(count,12);
this.oldPen = this.points[count].p;
this.oldColour = this.points[count].lc;
this.oldX = this.points[count].x;
this.oldY = this.points[count].y;
this.oldRotation = this.points[count].b;
this.turtleSpeed = this.points[count].s;
this.newPen = this.points[count+1].p;
this.newColour = this.points[count+1].lc;
this.newX = this.points[count+1].x;
this.newY = this.points[count+1].y;
this.changRot = this.points[count+1].b;
this.turtleSpeed = this.points[count+1].s;
this.count++;
this.veryOldX = this.oldX;
this.veryOldY = this.oldY;
//path.add(new paper.Point(veryOldX, veryOldY));

if(newPen!=oldPen || newColour != oldColour){
if (this.newPen != this.oldPen || this.newColour != this.oldColour){
//Changing pen - start a new path
this.path = new paper.Path();
this.path.strokeWidth = 3;

this.path.add(new paper.Point(oldX, oldY));
this.path.add(new paper.Point(this.oldX, this.oldY));
}

// Good test command to see what the input is from the string
Expand Down Expand Up @@ -350,7 +301,7 @@ function TurtleDrawing(data, canvas_element, grid_button, help_button) {

//rotate turtle, current is the exact centre of the turtle
if (changRot != 0 && that.turtleShow==1){
var current = new paper.Point(oldX, oldY);
var current = new paper.Point(that.oldX, that.oldY);

if(changRot < 0){

Expand Down Expand Up @@ -404,7 +355,7 @@ function TurtleDrawing(data, canvas_element, grid_button, help_button) {
if(that.newPen == 1){
that.path.add(new paper.Point(that.oldX, that.oldY));
that.turtle.position = new paper.Point(that.oldX, that.oldY);
that.path.strokeColor = newColour;
that.path.strokeColor = that.newColour;
}
} else {
// done animating this command
Expand Down

0 comments on commit f4b6d2f

Please sign in to comment.