Difference between revisions of "Activities/Turtle Art/Tutorials/Turtle Art Code for Turing Machine"

From Sugar Labs
Jump to navigation Jump to search
(Add Turtle Art action images)
m (Copy edit)
Line 10: Line 10:
  
 
[[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.
 +
 +
[[File:Program.png|thumb|none|Program action]]
  
 
* The Tape action writes the initial tape. User can change values in repeat statements to change arguments.
 
* The Tape action writes the initial tape. User can change values in repeat statements to change arguments.
Line 15: Line 19:
 
[[File:Tape.png|thumb|none|Tape action]]
 
[[File:Tape.png|thumb|none|Tape 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
+
* The Execute action repeats reading out the next program step until the halt state is reached.
 
 
[[File:Program.png|thumb|none|Program action]]
 
 
 
* The Execute action carries out the next program step until the halt state is reached
 
 
[[File:Execute.png|thumb|none|Execute action]]
 
[[File:Execute.png|thumb|none|Execute action]]
  
* The ToTape action Move turtle to current cell on tape
+
* The ToTape action moves the turtle to the current cell on the tape. Startup default is cell 1.
 
[[File:ToTape.png|thumb|none|ToTape action]]
 
[[File:ToTape.png|thumb|none|ToTape action]]
  
* The ToProgram action Move Turtle to beginning of current program row to execute
+
* 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 Write current color to current cell, and move to next cell
+
* The WriteCell action writes the current color to the current cell, and moves to the next cell to the right
  
 
[[File:WriteCell.png|thumb|none|WriteCell action]]
 
[[File:WriteCell.png|thumb|none|WriteCell action]]
  
* The WriteSymbol action Write current color in cell without moving
+
* The WriteSymbol action writes the current color in the current cell without moving
  
 
[[File:WriteSymbol.png|thumb|none|WriteSymbol action]]
 
[[File:WriteSymbol.png|thumb|none|WriteSymbol action]]
  
* The ReadPixel action Read RGB values of pixel to stack, pop to variables
+
* 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.
  
 
[[File:ReadPixel.png|thumb|none| ReadPixelaction]]
 
[[File:ReadPixel.png|thumb|none| ReadPixelaction]]
  
* The SetValue action Find value of cell symbol from RGB numbers
+
* 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 Read next Move direction from program table
+
* 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 Read next Symbol to write from program table
+
* 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 Read next State from program table
+
* 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 Move left or right and set cell number of new location
+
* The NewCell action moves the head (the Turtle) left or right, 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 Write Step number, Symbol, Move, State, Cell number on new log line in black, saving and restoring
+
* 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]]

Revision as of 16:17, 30 June 2011

Turtle Art Code for Turtle Art Turing Machine

Click thumbnails to see full-size code blocks.

  • The Start action is the main procedure
Start action
  • The Setup action defines and initializes variables, and sets the orientation of the turtle
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 action
  • The Tape action writes the initial tape. User can change values in repeat statements to change arguments.
Tape action
  • The Execute action repeats reading out the next program step until the halt state is reached.
Execute action
  • The ToTape action moves the turtle to the current cell on the tape. Startup default is cell 1.
ToTape action
  • The ToProgram action moves the Turtle to the beginning of the current program row to execute. Startup default is row 1
ToProgram action
  • The WriteCell action writes the current color to the current cell, and moves to the next cell to the right
WriteCell action
  • The WriteSymbol action writes the current color in the current cell without moving
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.
ReadPixelaction
  • The SetValue action finds the value of the current cell's symbol from RGB numbers provided by ReadPixel.
SetValue action
  • The SetMove action reads the next Move direction from a program table entry in column 1.
SetMove action
  • The SetSymbol action reads the next Symbol to write from a program table entry in column 2.
SetSymbol action
  • The SetState action reads the next State from a program table entry in column 3.


SetState action
  • The NewCell action moves the head (the Turtle) left or right, and sets the cell number for the new location
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 action