X SOURCE CODE

BACK TO X

Turtle Procedures Observer Procedures

turtles-own
[yvel ypos k time]

to setup
setc red
setx who - screen-half-width
setyvel 0
setypos 0
setk 1
settime 0
if xcor = screen-half-width
[setc blue]
if xcor = (-1 * screen-half-width)
[setc green]
end

to go
drive-force
if color = red
   [setyvel
      yvel
      + (k * (((ypos-of (who - 1)) - ypos)
          + ((ypos-of (who + 1)) - ypos)))
    setyvel ((1000 - friction) / 1000) * yvel
    setypos ypos + yvel
    sety ypos
    ifelse (abs ypos) <= screen-half-height
      [st]
      [ht]]
end

to drive-force
if color = green
   [settime time + 1
    setypos amplitude * (sin freq * time)
    sety ypos]
end

to setup
ca
crt screen-width
ask-turtles [setup]
end