Changes

m
Line 1: Line 1: −
==Turtle Art Code for Turtle Art Turing Machine==
+
==Turtle Art Code for [[Activities/TurtleArt/Tutorials/Turtle_Art_Turing_Machine| Turtle Art Turing Machine]]==
   −
Click thumbnails to see full-size code blocks.
+
Click thumbnails to see full-size action code. You can also compare this with the [[Activities/TurtleArt/Tutorials/Logo_Code_for_Turtle_Art_Turing_Machine|Logo code]] for the same Turing Machine, saved from Turtle Art and commented.
   −
* The Start action is the main procedure
+
==Start==
 +
 
 +
The Start action is the main procedure that clears all previous computation and graphics, puts the Turtle in its default starting position, and then calls for preparation (Setup, Program, Tape) and execution of the Turing Machine.
    
[[File:Start.png|thumb|none|Start action]]
 
[[File:Start.png|thumb|none|Start action]]
   −
* The Setup action defines and initializes variables, and sets the orientation of the turtle
+
==Setup==
 +
 
 +
The Setup action defines and initializes variables, and sets the orientation of the turtle
    
[[File:Setup.png|thumb|none|Setup action]]
 
[[File:Setup.png|thumb|none|Setup action]]
   −
* The Program action followed by the stack1 action writes the program table line by line. This is divided in two so that the segments fit in the Turtle Art workspace. Users who understand Turing Machine programming, or have other example Turing Machines to test, can edit this.
+
==Program==
 +
 
 +
The Program action followed by the stack1 action writes the program table line by line. This is divided in two so that the segments fit in the Turtle Art workspace. Users who understand Turing Machine programming, or have other example Turing Machines to test, can edit this. For Turing Machine programs larger than this example, use a Python block with a table, so that Program can read values and write symbols in a simple loop, rather than having each individual value appear literally in the code.
    
[[File:Program.png|thumb|none|Program action]]
 
[[File:Program.png|thumb|none|Program action]]
   −
* The Tape action writes the initial tape. User can change values in repeat statements to change arguments.
+
==Tape==
 +
 
 +
The Tape action writes the initial tape. User can change values in repeat statements to change arguments. Longer and more complex tapes for other Turing Machines can be written from Python tables.
    
[[File:Tape.png|thumb|none|Tape action]]
 
[[File:Tape.png|thumb|none|Tape action]]
   −
* The Execute action repeats reading out the next program step until the halt state is reached.
+
==Execute==
 +
 
 +
The Execute action repeats reading out the next program step until the halt state is reached. It contains added Wait blocks to make the main steps in execution clearer to someone watching. Removing them will of course make the Machine run faster, but will make it much more difficult to follow.
 +
 
 
[[File:Execute.png|thumb|none|Execute action]]
 
[[File:Execute.png|thumb|none|Execute action]]
   −
* The ToTape action moves the turtle to the current cell on the tape. Startup default is cell 1.
+
==ToTape==
 +
 
 +
The ToTape action moves the turtle to the current cell on the tape. Startup default is cell 0.
 +
 
 
[[File:ToTape.png|thumb|none|ToTape action]]
 
[[File:ToTape.png|thumb|none|ToTape action]]
   −
* The ToProgram action moves the Turtle to the beginning of the current program row to execute. Startup default is row 1
+
==ToProgram==
 +
 
 +
The ToProgram action moves the Turtle to the beginning of the current program row to execute. Startup default is row 1
    
[[File:ToProgram.png|thumb|none|ToProgram action]]
 
[[File:ToProgram.png|thumb|none|ToProgram action]]
   −
* The WriteCell action writes the current color to the current cell, and moves to the next cell to the right
+
==WriteCell==
 +
 
 +
The WriteCell action writes the current color to the current cell, and moves to the next cell to the right. The Program and Tape actions use this.
    
[[File:WriteCell.png|thumb|none|WriteCell action]]
 
[[File:WriteCell.png|thumb|none|WriteCell action]]
   −
* The WriteSymbol action writes the current color in the current cell without moving
+
==WriteSymbol==
 +
 
 +
The WriteSymbol action writes the current color in the current cell on the tape without moving, as part of executing a line of instructions from the program
    
[[File:WriteSymbol.png|thumb|none|WriteSymbol action]]
 
[[File:WriteSymbol.png|thumb|none|WriteSymbol action]]
   −
* The ReadPixel action reads the RGB values of the pixel under the Turtle, and puts them on the stack. It then pops the results and stores them in the variables R, G, and B.
+
==ReadPixel==
 +
 
 +
The ReadPixel action reads the RGB values of the pixel under the Turtle, and puts them on the stack. It then pops the results and stores them in the variables R, G, and B. This is used for reading program instructions and tape symbols.
    
[[File:ReadPixel.png|thumb|none| ReadPixelaction]]
 
[[File:ReadPixel.png|thumb|none| ReadPixelaction]]
   −
* The SetValue action finds the value of the current cell's symbol from RGB numbers provided by ReadPixel.
+
==SetValue==
 +
 
 +
The SetValue action finds the value of the current cell's symbol from RGB numbers provided by ReadPixel.
    
[[File:SetValue.png|thumb|none|SetValue action]]
 
[[File:SetValue.png|thumb|none|SetValue action]]
   −
* The SetMove action reads the next Move direction from a program table entry in column 1.
+
==SetMove==
 +
 
 +
The SetMove action reads the next Move direction from a program table entry in column 1.
    
[[File:SetMove.png|thumb|none|SetMove action]]
 
[[File:SetMove.png|thumb|none|SetMove action]]
   −
* The SetSymbol action reads the next Symbol to write from a program table entry in column 2.
+
==SetSymbol==
 +
 
 +
The SetSymbol action reads the next Symbol to write, from a program table entry in column 2.
    
[[File:SetSymbol.png|thumb|none|SetSymbol action]]
 
[[File:SetSymbol.png|thumb|none|SetSymbol action]]
   −
* The SetState action reads the next State from a program table entry in column 3.
+
==SetState==
 +
 
 +
The SetState action reads the next State from a program table entry in column 3.
       
[[File:SetState.png|thumb|none|SetState action]]
 
[[File:SetState.png|thumb|none|SetState action]]
   −
* The NewCell action moves the head (the Turtle) left or right, and sets the cell number for the new location
+
==NewCell==
 +
 
 +
The NewCell action moves the head (the Turtle) left or right as directed by the program, and sets the cell number for the new location
    
[[File:NewCell.png|thumb|none|NewCell action]]
 
[[File:NewCell.png|thumb|none|NewCell action]]
   −
* The Log action writes Step number, Symbol, Move, State, Cell number on a new log line in black, saving and restoring the current Symbol color.
+
==Log==
 +
 
 +
At each program step, the Log action writes Step number, Symbol, Move, State, Cell number on a new log line in black, saving and restoring the current Symbol color.
    
[[File:Log.png|thumb|none|Log action]]
 
[[File:Log.png|thumb|none|Log action]]
1,009

edits