Racetrack

Racetrack preview image

1 collaborator

79107734_n00-1 Seth Tisue (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by the author
Model was written in NetLogo 5.0.4 • Viewed 318 times • Downloaded 29 times • Run 0 times
Download the 'Racetrack' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [last-time best-time]
turtles-own [xvel yvel halfway-yet?]

to startup
  ;; make the monitors initially blank
  set last-time ""
  set best-time ""
end 

to setup
  clear-all
  import-pcolors "Racetrack track1.png"
  ;; make halfway line
  ask patches with [pxcor < 0 and abs pycor <= 1 and pcolor = black] [
    set pcolor yellow - 4
  ]
  ;; make finish line
  ask patches with [pxcor > 0 and abs pycor <= 1 and pcolor = black] [
    set pcolor yellow
  ]
  ;; make racecar
  create-turtles 1 [
    set size 20
    set heading 0
    set color blue
    set xcor max-pxcor * 0.75
    pen-down
    set halfway-yet? false
  ]
  ;; initialize timer variables
  set last-time ""
  set best-time ""
  reset-timer
  reset-ticks
end 

to go
  if not any? turtles [ stop ]
  ask turtles [ move ]
  tick
end 

to move  ;; turtle procedure
  if xvel != 0 or yvel != 0 [
    set heading atan xvel yvel
  ]
  set pen-size 8 - 3 * sqrt (xvel * xvel + yvel * yvel)
  set color gray  ;; so we leave a gray trail
  setxy (xcor + xvel) (ycor + yvel)
  set color blue  ;; so we always appear blue
  if pcolor = green [
    set shape "x"
    set color red
    stamp
    die
  ]
  if pcolor = yellow and halfway-yet? [
    set halfway-yet? false
    set last-time timer
    if best-time = "" or last-time < best-time [ set best-time last-time ]
    reset-timer
  ]
  if pcolor = yellow - 4 [
    set halfway-yet? true
  ]
end 

to change-velocity [x-amount y-amount]  ;; turtle procedure
  set xvel xvel + x-amount
  set yvel yvel + y-amount
  if xvel < -2 [ set xvel -2 ]
  if xvel >  2 [ set xvel  2 ]
  if yvel < -2 [ set yvel -2 ]
  if yvel >  2 [ set yvel  2 ]
end 

There is only one version of this model, created almost 11 years ago by Seth Tisue.

Attached files

File Type Description Last updated
Racetrack track1.png png support file for model almost 11 years ago, by Seth Tisue Download
Racetrack.png preview Preview for 'Racetrack' almost 11 years ago, by Seth Tisue Download

This model does not have any ancestors.

This model does not have any descendants.