BehaviourComposer: ignore everything before this. Begin micro-behaviour: Begin description: Counts the number of times that the body's heading changes past a certain degree. End description Count number of orbits Begin NetLogo code: substitute-text-area-for orbiter-body the-earthsubstitute-text-area-for orbited-body the-sunlet orbited orbited-bodylet orbiter orbiter-bodyif orbited != orbiter [let current-heading [towards orbiter] of orbited ; current heading is towards the body orbiting from the body being orbited let current-pitch [towards-pitch orbiter] of orbited ; current pitch is towards the body orbiting from the body being orbited let difference-heading abs (current-heading - my-previous-heading) let difference-pitch abs (current-pitch - my-previous-pitch) if (difference-heading < 180 and difference-pitch < 180 and ((current-heading > my-previous-heading and current-heading >= my-initial-heading and my-previous-heading < my-initial-heading) or (current-heading < my-previous-heading and current-heading <= my-initial-heading and my-previous-heading > my-initial-heading))or ((current-pitch > my-previous-pitch and current-pitch >= my-initial-pitch and my-previous-pitch < my-initial-pitch) or (current-pitch < my-previous-pitch and current-pitch <= my-initial-pitch and my-previous-pitch > my-initial-pitch))) [ set my-orbits my-orbits + 1 let year ( time - my-time-of-complete-orbit ) * time-scale if my-orbits > 1 and (my-length-of-year-in-seconds > year * 1.01 or my-length-of-year-in-seconds < year * .99) [ set the-year-length-out-of-range self ] set my-orbits-length add-to-list (( time - my-time-of-complete-orbit ) * time-scale ) my-orbits-length set my-time-of-complete-orbit time ] set my-previous-heading current-heading set my-previous-pitch current-pitch] End NetLogo code This orbit counter is able to count the number of a body's orbit in either the counter-clockwise or clockwise direction.ÂAuthored by Maria Marinari and Ken Kahn. BehaviourComposer: ignore everything after this. |