Courses/CS 461/Winter 2006/Brian Smith/Week 1

From CSWiki

Jump to: navigation, search

This is a fairly basic example, nothing as advanced as others. It will require more studying and coding before I'm as proficient in NetLogo.

Image:Brian_Smith_Color-bars.gif

; Week 1 - Getting familiar with NetLogo - Brian Smith
; This model maps the position of the butterfly and the
; mouse to hue and brightness values for columns and rows.
; The idea originally came from a Processing example.

;;;;; SETUP ;;;;;

globals [ x y ]

to setup
  clear-all
  setup-butterfly
end

to setup-butterfly
  crt 1
  ask turtle 0 [
    set shape "butterfly"
    set color white
    set size 3
  ]
end

;;;;; RUN ;;;;;

to go
  move-butterfly
  read-mouse
end

to move-butterfly
  ask turtle 0 [
    rt random-float 40 - random-float 40
    forward 1
    set x pxcor
    set y pycor
  ]
  ask patches with [pxcor = x] [
    set pcolor hsb 
      ((x + screen-edge-x) / screen-size-x)
      1.0 
      ((y + screen-edge-y) / screen-size-y) 
  ]
end

to read-mouse
  if mouse-inside? [
    ask patches with [pycor = (round mouse-ycor)] [
      set pcolor hsb 
        (((round mouse-ycor) + screen-edge-y) / screen-size-y)
        1.0 
        (((round mouse-xcor) + screen-edge-x) / screen-size-x)
    ]
  ]
end
Personal tools