Squeak Class Documentation category index | class index  
 
StarSqueakTurtle
  category: StarSqueak-Kernel
  superclass: Object
  subclasses: AntColonyTurtle DiffusionTurtle SlimeMoldTurtle TermiteTurtle TreeTurtle

I represent a "creature" that can move about on the surface of a StarSqueak world. I have a position and a heading (direction), and respond commands such as "turnRight:" and "forward:" by turning or moving. I also have an imaginary pen that can draw a trail as I move. In StarSqueak, turtles are born with random positions and headings.

Here are some expressions to try in a workspace:
w _ StarSqueakMorph new openInWorld. "make an empty world"
w makeTurtles: 100. "create 100 turtles"
w turtlesDo: [:t | t forward: 1]. "tell all turtles to take a step"
w turtlesDo: [:t | t goto: 50@50]. "tell all turtles to go to 50@50"
w turtlesDo: [:t | t forward: 10]. "tell all turtles to take 10 steps"

Structure:
world StarSqueakMorph the world that owns this turtle
who integer unique id
x number x position in world
y number y position in world
wrapX float private; used for wrapping in x
wrapY float private; used for wrapping in y
headingRadians float heading in radians
color color turtle color and its pen color
penDown boolean true if drawing a pen trail
nextTurtle StarSqueaktTurtle private; used to make linked list of turtles

instance methods
  accessing
  asPoint
color
color:
heading
heading:
nextTurtle
nextTurtle:
who
who:
x
x:
y
y:

  commands
  die
forward:
forwardOne
goto:
penDown
penUp
random:
replicate
stop
turnLeft:
turnRight:
turnTowards:
turnTowardsStrongest:

  initialization
  initializeWorld:who:

  patches
  get:
increment:by:
patchBrightness
patchBrightness:
patchColor
patchColor:
set:to:

  sensing
  distanceTo:
turtleCountHere

class methods
  no messages
 

instance methods
  accessing top  
 

asPoint


 

color


 

color:


 

heading

Answer my heading in degrees.


 

heading:

Set my heading in degrees. Like a compass, up or north is 0 degrees and right or east is 90 degrees.


 

nextTurtle

The nextTurtle slot is used to make a linked list of turtles at a given patch.


 

nextTurtle:

The nextTurtle slot is used to make a linked list of turtles at a given patch.


 

who


 

who:


 

x


 

x:


 

y


 

y:


  commands top  
 

die

Delete this turtle at the end of the current cycle. The turtle will finish running all demons for the current cycle before it dies.


 

forward:

Move the given distance in the direction of my heading.


 

forwardOne

Move one turtle step in the direction of my heading.


 

goto:

Jump to the given location.


 

penDown

Put down this turtle's pen. That is, the turtle will leave a trail the same color as itself when it moves.


 

penUp

Lift this turtle's pen. The turtle will stop leaving a trail.


 

random:

Answer a random integer between 0 and range.


 

replicate

Add an exact replica of this turtle to the world. The new turtle does not become active until the next cycle.


 

stop

Stop running.


 

turnLeft:

Turn left by the given number of degrees.


 

turnRight:

Turn right by the given number of degrees.


 

turnTowards:

Turn to face the given point, turtle, or patch.


 

turnTowardsStrongest:

Turn to point toward the nearby patch having the highest value of the given patch variable. This command uses only local information. In particular, it only considers patches within 'sniffRange' of this turtles location. For example, with the default 'sniffRange' of 1, it only considers the immediate neighbors of the patch this turtle is on.


  initialization top  
 

initializeWorld:who:


  patches top  
 

get:

Answer the value of the given patch variable below this turtle.


 

increment:by:

Increment the value of the given patch variable below this turtle by the given amount (positive or negative).


 

patchBrightness

Answer the brightness of the patch below this turtle, where 0 is black and 100 is full brightness.


 

patchBrightness:

Set the brightness of the patch below this turtle to the given value, where 0 is black and 100 is full brightness.


 

patchColor

Answer the color of the patch below this turtle.


 

patchColor:

Paint the patch below this turtle with the given color.


 

set:to:

Set the value of the given patch variable below this turtle to the given value.


  sensing top  
 

distanceTo:

Answer the distance from this turtle to the given point.


 

turtleCountHere

Answer a collection of turtles at this turtle's current location, including this turtle itself.


class methods
  no messages top