Activities/Turtle Art/Tutorials/Turtle Art Code for Turing Machine

From Sugar Labs
< Activities‎ | Turtle Art‎ | Tutorials
Revision as of 15:17, 30 June 2011 by Mokurai (talk | contribs) (Copy edit)
Jump to navigation Jump to search

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.
  • 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