locomotion-5g


Information

Created with NetLogo version NetLogo 4.0.4
Running with NetLogoLite.jar version 404.


WHAT IS IT


A tool to explore bipedal locomotion as a product of simple pendulum-like motion
A demonsration of procedureal animation (vs. motion-capture or hand-animated)
Connected amatures are made to swing at selected frequencies and phases, generating movement cycles that suggest running, walking, swimming, and the like.

Procedures

NetLogo Version: NetLogo 4.0.4

;;;; SUMMARY
;; These codes were made for walkin'
;;;; COPYRIGHT
;; Copyright (C) 2006 James P. Steiner
;; All rights reserved.
;;
;;

globals
[
  top clock
  body
  oldmy
  surface
  altitude
  dvy
  linkers
  greeting?
  direction-1
  direction-2
  direction-0
  period-0
  period-1
  period-2
  period
]

breed [ vectors ]
breed [ segments ]


turtles-own
[

]

segments-own
[ vx vy
  min-angle
  max-angle
  phase
  parent
  child
  tag
]

patches-own
[

]

to startup
   setup
end
   
to setup
   ca
   set clock 0
   set-default-shape segments limb-shape
   set-default-shape vectors "line-half"
   set linkers 3
   set period 50
   
   create-segments 1
   [ set parent nobody set color who * 30 + limb-color ;; (quick&dirty.. need who-agnostic method)
     hatch 1
     [ set parent myself set color who * 30 + limb-color
       hatch 1
       [ set parent myself set color who * 30 + limb-color
         hatch 1
         [ set parent myself set color who * 30 + limb-color
           set child nobody
           set size 0
         ]
       ]
       set child turtle 2
     ]
     set child turtle 1
   ]
   ;; create shadow leg 
   ;; (hack -- need who-agnostic method)
   ask segments [ hatch 1 [ set parent turtle (who - 1)] set color gray]
   create-vectors 1
   [ set body self
     setxy 0 0
     set size ( sum [ size ] of segments ) * .75
   ]
   go
   greeting true
end

to go
   every (1 / 30) [
   no-display
   if greeting? != false [ greeting false ]

   let segs sort-by [ [who] of ?1 < [who] of ?2 ] segments
   foreach segs
   [ ask ? 
   [ let s# (who mod (linkers + 1)) 
     ifelse s# = 0
     [ setvxy 0 0 ]
     [ setvxy segx segy ]
     if s# != linkers
     [ ifelse s# = who
       [ set heading new-heading clock ]
       [ set heading new-heading (clock + 3.6 + symmetry )]
       if size != .01 + slider "length" 
       [ set size .01 + slider "length" ]
     ]
   ] ]
   if [shape] of turtle 0 != limb-shape [ ask segments [ set shape limb-shape ] ]
   let bottom -.75 * max-pycor
   let mx 0
   let my 0
   let bx 0
   let by 0 
   ifelse attachment = 1
   [ set mx mean [ vx ] of segments
     set my mean [ vy ] of segments 
      
     set bx 0 - (mx)
     set by 0 - (my )  
   ]
   [ if attachment = 2 or attachment = 3
     [ set mx mean [ vx ] of segments 
       set my min [ vy ] of segments 
       let mxy max [ vy ] of segments 
       let span (- my) ;; height from ground to hips
       let gap abs (bottom + span)
       ifelse attachment = 2 
       [ ;; no gravity, snap to bottom
         set by bottom + span ]
       [ ;; gravity, accellerate downward
         ifelse altitude > span
         [ set dvy dvy  - gravity * slow-mo
           set altitude altitude + dvy
         ]
         [ set altitude span set dvy dvy * -0.25
         ]
         set by bottom + altitude       
       ]
       set bx 0 - mx
       set oldmy gap
     ]
   ]
   ask segments [ setxy (bx + vx ) (  by + vy ) ]
   
   
   
   ask body
   [ setxy [xcor] of turtle 0 [ycor] of turtle 0
     set heading 180 + mean-headings turtle 0 turtle (linkers + 1 ) 
   ]
   if trace? 
   [ ask segments with [ color > gray ]
    [ pd jump 0.1 jump -0.1 pu ]
   ]
   display
   
   if time-advance [ set clock clock + speed * slow-mo]
   ]
end


to-report segx
   report [ vx + dx * slider "length" ] of parent
end   

to-report segy 
   report [ vy + dy * slider "length" ] of parent
end

to-report slider [ name ]
   report run-result (word name "-" (who mod (linkers + 1) ) )
end      

to-report new-heading [ freq ]
   let half-sweep .5 * slider "sweep"
   let   new-head (   slider "angle"
                    +  slider "sweep"
                            * (sin ( slider "phase" + freq * period ))
                  )
   if who mod (linkers + 1 ) != 0
   [ set new-head new-head + [heading] of parent ]
   report new-head 
end        

to-report mean-headings [ a b ]
   let ha [heading] of a
   let hb [heading] of b
   report atan ( .5 * (sin ha + sin hb) ) 
               ( .5 * (cos ha + cos hb) )
end
               
to setvxy [ xx yy ]
   set vx xx set vy yy
end   


to generate-cycle-parameters-code
   clear-output
   foreach
   [  "angle-0" "sweep-0" "phase-0" "direction-0" "period-0" "length-0"
      "angle-1" "sweep-1" "phase-1" "direction-1" "period-1" "length-1"
      "angle-2" "sweep-2" "phase-2" "direction-2" "period-2" "length-2"
     "speed" "symmetry"
   ]
   [ let line-out (word "set " ? " " run-result ? )
     output-print line-out
     ;;; print line-out
   ]
end


to movie-prep
   if movie-status != false
   [ movie-cancel ]
   let movie-file user-new-file
   if movie-file = false [ stop ]
   let fps user-input "Enter frame-rate"
   if fps = false [ stop ]
   movie-set-frame-rate fps
   movie-start movie-file
end


to greeting [ show? ]
   ifelse show?
   [ ask patch max-pxcor (max-pycor - 1) [ set plabel "Click  GO  to begin animation."  ]
     set greeting? true
   ]
   [ ask patch max-pxcor (max-pycor - 1) [ set plabel "" ]
     set greeting? false
   ]
end   
    


                    


Download Link

View or download the complete model file (to download: right-click, save-link-as):
-- Download locomotion-5g --