Bounce Lottery

No preview image

1 collaborator

Dsc_0179_-_version_2 Jacob Wilkes (Author)

Tags

(This model has yet to be categorized with any tags)
Child of model Bounce Lottery preview imageBounce Lottery
Model group LS426_2013 | Visible to everyone | Changeable by everyone
Model was written in NetLogo 5.0.3 • Viewed 334 times • Downloaded 45 times • Run 0 times
Download the 'Bounce Lottery' modelDownload this modelEmbed this model

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


Original Model

The original model was a demo that showed how to make turtles "bounce" off walls.

Modification

Our modification takes an input from a GoGo Board that causes the turtles to change colors insync with a cycle of flashing LEDs. This is accomplished by two commands that modify the original model.

A "lights2" command talks to the GoGo Board outputs (three LEDs) and instructs them to cycle through on and off states, which creates a loop of flashing blue, green, and red lights.

The "talk-to" command talks to the onscreen turtles and instructs them to match color with the flashing lights.

Buttons

setup

setups the bounce model (creates border and turtles)

go

starts the turtles "bouncing" around the screen

leave trace

tells the turtles to put their pen up or down

Set up GoGo Board

connects the GoGo board to the computer

lights

begins the light sequence (input and output from GoGo board)

turnoff

turns all outputs (lights) on the GoGo board off

REFLECTION

In the most general sense, we learned that there were many possibilities that we could explore in next weeks experience. We were excited to learn how the sample models made games and simulations by decomposing the problem and translating it into NetLogo language. Moreover, we learned that our experience with LOGO helped us orient ourselves in NetLogo. NetLogo, to some extent, is even more intuitive because of the _spelling-check function in the code tab.

In terms of the specific model that we worked on, we learned much in our debugging experience. For example, after we added the color-changing elements into our codes, the turtles froze whenever they changed into another color. We were having a hard time figuring out whether we needed a longer or shorter interval, and how to sync the commands from different procedures. We learned that the order of commands in the command block was very important. In our second version of procedures, we put gogo:output-port-off at the very end. As a result, all lights were off when there was no input in sensor 1.

Comments and Questions

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

Click to Run Model

extensions[gogo]

globals [
turtlecolor
]

to setup
  clear-all
  set-default-shape turtles "circle"
  draw-walls
  crt 5                                 ;; create some turtles
    [ randomize ]                       ;; place them randomly
  reset-ticks
end 

; draws the boundaries (walls) of the "billiard table"

to draw-walls
  ; draw left and right walls
  ask patches with [abs pxcor = max-pxcor]
    [ set pcolor blue ]
  ; draw top and bottom walls
  ask patches with [abs pycor = max-pycor]
    [ set pcolor blue ]
end 

; set random location

to randomize
  setxy random-xcor random-ycor
  if pcolor = blue       ; if it's on the wall...
    [ randomize ]        ; ...try again
end 

to go
  ask turtles [
    ifelse leave-trace?             ;; the turtle puts its pen up or down depending on the
      [ pd ]                        ;; value of the LEAVE-TRACE? switch
      [ pu ]
    bounce
    fd 0.1
  ]
  tick
end 

;; this procedure checks the coordinates and makes the turtles
;; reflect according to the law that the angle of reflection is
;; equal to the angle of incidence

to bounce  ;; turtle procedure
  ; check: hitting left or right wall?
  if abs [pxcor] of patch-ahead 0.1 = max-pxcor
    ; if so, reflect heading around x axis
    [ set heading (- heading) ]
  ; check: hitting top or bottom wall?
  if abs [pycor] of patch-ahead 0.1 = max-pycor
    ; if so, reflect heading around y axis
    [ set heading (180 - heading) ]
end 

to lights2
  let counter 0
  while [ gogo:sensor 1 < 50] [ 
    talk-to counter
    gogo:output-port-off
    set counter counter + 1 
    talk-to counter
    gogo:output-port-on
    gogo:beep
    repeat 5 [wait .005 go]
  ]
end 

to talk-to [counter]
  if counter mod 3 = 0
  [ gogo:talk-to-output-ports["a"] ask turtles [set color blue]
]
  if counter mod 3 = 1
  [ gogo:talk-to-output-ports["b"] ask turtles [set color green]
]
  if counter mod 3 = 2
  [ gogo:talk-to-output-ports["c"] ask turtles [set color red]
]
end 

to setupturtle
gogo:open "/dev/tty.usbmodem1421"
end 

to turnoff
gogo:talk-to-output-ports [ "a" "b" "c" ]
gogo:output-port-off
end 


  ;ask turtles set color red

; Public Domain:
; To the extent possible under law, Uri Wilensky has waived all
; copyright and related or neighboring rights to this model.

There is only one version of this model, created over 12 years ago by Jacob Wilkes.

Attached files

No files

Parent: Bounce Lottery

This model does not have any descendants.

Graph of models related to 'Bounce Lottery'