globals [ heading-name posx posy vx vy ax ay speed time all-force force-amt old-shape old-force-of-friction old-other-forces move-food? show-trail? ;can be on/off old-posx old-posy old-speed ] breed [ rocket ] breed [ arrow ] arrow-own [ age x y] patches-own [ path? ] ;;;;;;;;;;;;;;;;;;;;; ;; Setup Functions ;; ;;;;;;;;;;;;;;;;;;;;; to startup ask turtles [die] create-rocket set time 0 set all-force 0 set speed 0 ask patches [set pcolor black set path? false] ; ask patches with [pycor > 2 or pycor < -2] [set pcolor 7] set old-shape food set old-force-of-friction force-of-friction set move-food? false set show-trail? false set fade-arrows? false set fade-trail? false end to go if not move-food? [ without-interruption [ ; ask arrow [ifelse (x != xcor or y != ycor) [hide-turtle] [show-turtle]] if old-shape != food [ set old-shape food ask rocket [set shape food] ] ;; to change show-trail? ifelse force-of-friction = 0 [set show-trail? false] [set show-trail? true] if (old-force-of-friction != force-of-friction) [ set old-force-of-friction force-of-friction ask patches with [not path?] ; [set pcolor random ((0 + force-of-friction * 2)) ] [ifelse (pxcor mod 2 > 0) xor (pycor mod 2 > 0) [set pcolor force-of-friction ] [ ifelse (force-of-friction = 0) [set pcolor 0] [set pcolor force-of-friction - 1] ] ] ] move-rocket fade ] ] end to do-plots set-current-plot "velocity" set-current-plot-pen "x" plotxy time vx set-current-plot-pen "y" plotxy time vy set-current-plot "acceleration" set-current-plot-pen "x" plotxy time ax set-current-plot-pen "y" plotxy time ay set time time + 1 end to-report rocket-heading report heading-of one-of rocket end to move-rocket locals [dt constant] ; set dt 0.1 set dt 0.062 set constant force-of-friction / 20 ask rocket [ set old-posx posx set old-posy posy set old-speed speed ; sin and cos are switched, because netlogo's heading is ; different than the other one ; heading is determined by arrow presses: 0 N, 90 E, 180 S, 270 W ;;print heading set ax force-amt * sin (heading) set ay force-amt * cos (heading) ;;my version doesn't have gravity but it might be cool to include it ;; if (gravity != 0) [set ay ay - gravity] ;; note gravity might need to be reduced (e.g., like you divide by 20 for friction) ;; if (gravity != 0) [set ay ay - gravity / 20 ] ;; I tried gravity of 9.8 and dividing by 20 worked pretty well if (constant != 0 and vx != 0) [ifelse vx > 0 [set ax ax - constant * abs (sin atan vx vy) ] [set ax ax + constant * abs (sin atan vx vy) ] ];note constant is set to be force-of-friction / 20 if (constant != 0 and vy != 0) [ifelse vy > 0 [set ay ay - constant * abs (cos atan vx vy)] [set ay ay + constant * abs (cos atan vx vy)] ] set vx vx + ax * dt set vy vy + ay * dt set speed sqrt ( (vx * vx) + (vy * vy) ) ;;print speed set posx posx + vx * dt set posy posy + vy * dt set force-amt 0 setxy posx posy if heading = 0 [set heading-name "N"] if heading = 45 [ set heading-name "NE"] if heading = 90 [set heading-name "E"] if heading = 135 [set heading-name "SE"] if heading = 180 [set heading-name "S"] if heading = 225 [set heading-name "SW"] if heading = 270 [set heading-name "W"] if heading = 315 [set heading-name "NW"] if show-trail? and vx != 0 and vy != 0 [ ask patch-here [set pcolor (15) set path? true] ] ifelse count arrow > 0 and count? [ ; set label (precision (distance one-of arrow with [age = 0]) 0) set label precision (sqrt( ( (x-of one-of arrow with [age = 0]) - posx ) * ( (x-of one-of arrow with [age = 0]) - posx ) + ( (y-of one-of arrow with [age = 0]) - posy ) * ( (y-of one-of arrow with [age = 0]) - posy ) ) ) 0 ] [ set label ""] ] do-plots end to fade every 3 [ if fade-trail? [ ask patches with [path?] [ set pcolor pcolor - 0.5 if pcolor mod 10 = 0 [ set path? false set pcolor force-of-friction ] ] ] if fade-arrows? [ ask arrow [ ; set age age + 1 set color color - 1 if color mod 10 = 0 [hide-turtle] ] ] ask arrow with [shape = "arrow"] [set shape "arrow-2"] ] end to show-force without-interruption [ set force-amt force * 10 ;show force-amt if force-amt != 0 [ ask arrow [set age 1] cct 1 [ set breed arrow set age 0 set shape "arrow" set size 2 ; set size (abs (force-for-food)) hide-turtle ; set age 0 if force-amt > 0 [ setxy posx posy set x posx set y posy set heading rocket-heading set color blue show-turtle ] if force-amt < 0 [ setxy posx posy set x posx set y posy set heading rocket-heading - 180 set color blue show-turtle ] ] ] ;show "begin show-force's move-rocket" move-rocket ;show "end show-force's move-rocket" ] end to north ask rocket [set heading 0 ] show-force end to south ask rocket [set heading 180 ] show-force end to east ask rocket [set heading 90 ] show-force end to west ask rocket [set heading 270 ] show-force end to startover ask rocket [ set vx 0 set vy 0 set force-amt 0 set label "" ] ask patches [set pcolor black set path? false] ;ask patches with [pycor > 2 or pycor < -2] [set pcolor 7] set-current-plot "velocity" clear-plot set-current-plot "acceleration" clear-plot set time 0 set all-force 0 ask arrow [die] ask patches [ set path? false ifelse (pxcor mod 2 > 0) xor (pycor mod 2 > 0) [set pcolor force-of-friction ] [ ifelse (force-of-friction = 0) [set pcolor 0] [set pcolor force-of-friction - 1] ] ] move-food end ;; Create a turtle, set its shape, color, and position ;; and tell the node what its turtle looks like and where it is to create-rocket cct 1 [ set breed rocket set label-color white setxy 0 0 set color white set heading 90 set posx xcor set posy ycor set old-posx posx set old-posy posy set size 5 set shape "donut" if heading = 0 [set heading-name "N"] if heading = 45 [ set heading-name "NE"] if heading = 90 [set heading-name "E"] if heading = 135 [set heading-name "SE"] if heading = 180 [set heading-name "S"] if heading = 225 [set heading-name "SW"] if heading = 270 [set heading-name "W"] if heading = 315 [set heading-name "NW"] ] set vx 0 set vy 0 set ax 0 set ay 0 set force-amt 0 end ;to create-arrow;; ; ask arrow [set age 0] ; cct 1 ; [ ; set breed arrow ; set age 1 ; set shape "arrow" ; set color red ; set size 1 ;; hide-turtle ; set age 0 ; ] ;end to-report velocity report sqrt (vx ^ 2 + vy ^ 2) end to move-food locals [time2 done?] set move-food? true set time2 0 set done? false ask patches with [max-pxcor - pxcor < 3 and max-pycor - pycor < 3] [set pcolor white] ask patch-at (max-pxcor - 1 ) (max-pycor - 1) [set plabel-color red ] ask patch-at (max-pxcor - 1 ) (max-pycor ) [set plabel-color black set plabel "Click"] ask patch-at (max-pxcor ) (max-pycor - 2) [set plabel-color black set plabel "to stop" ] ask rocket [ ask patch-here [ set path? false ifelse (pxcor mod 2 > 0) xor (pycor mod 2 > 0) [set pcolor force-of-friction ] [ ifelse (force-of-friction = 0) [set pcolor 0] [set pcolor force-of-friction - 1] ] ] ] while [not done?] [ every 1 [set time2 time2 + 1] if time2 > 10 [set done? true] ask patch-at (max-pxcor - 1) (max-pycor - 1) [set plabel (11 - time2) ] if mouse-down? and abs (mouse-xcor - xcor-of one-of rocket) < 3 and abs (mouse-ycor - ycor-of one-of rocket) < 3 [ while [mouse-down?] [ ask rocket [setxy mouse-xcor mouse-ycor] ] ask rocket [set posx xcor set posy ycor set old-posx posx set old-posy posy] ] if mouse-down? and abs (mouse-xcor + min-pxcor) < 3 and abs (mouse-ycor + min-pycor) < 3 [set done? true] ] ask patch-at (max-pxcor - 1) (max-pycor - 1) [set plabel ""] ask patch-at (max-pxcor - 1) (max-pycor ) [set plabel ""] ask patch-at (max-pxcor ) (max-pycor - 2) [set plabel "" ] ask patches with [(max-pxcor - pxcor < 3) and (max-pycor - pycor < 3)] [ ifelse (pxcor mod 2 > 0) xor (pycor mod 2 > 0) [set pcolor force-of-friction ] [ ifelse (force-of-friction = 0) [set pcolor 0] [set pcolor force-of-friction - 1] ] ] set move-food? false end @#$#@#$#@ GRAPHICS-WINDOW 17 62 534 600 13 13 18.8 1 16 1 1 1 0 1 1 1 -13 13 -13 13 CC-WINDOW 5 614 1157 709 Command Center 0 BUTTON 18 10 111 43 Go go T 1 T OBSERVER T NIL BUTTON 327 10 421 43 Start Over startover NIL 1 T OBSERVER T NIL BUTTON 662 139 729 183 N north NIL 1 T OBSERVER T NIL BUTTON 663 264 730 307 S south NIL 1 T OBSERVER T NIL BUTTON 761 189 824 238 E east NIL 1 T OBSERVER T NIL BUTTON 564 191 627 239 W west NIL 1 T OBSERVER T NIL PLOT 832 79 1148 335 velocity time NIL 0.0 10.0 0.0 5.0 true true PENS "x" 1.0 0 -13345367 true "y" 1.0 0 -2674135 true PLOT 597 391 833 581 acceleration time NIL 0.0 10.0 0.0 5.0 true true PENS "x" 1.0 0 -13345367 true "y" 1.0 0 -2674135 true MONITOR 617 65 692 114 x-velocity vx 3 1 SWITCH 720 12 859 45 fade-arrows? fade-arrows? 1 1 -1000 SLIDER 632 197 756 230 force force -5 5 1 1 1 NIL MONITOR 697 65 771 114 y-velocity vy 3 1 CHOOSER 151 10 289 55 Food Food "donut" "bagel" 0 SLIDER 622 334 762 367 force-of-friction force-of-friction 0 6 0 1 1 NIL SWITCH 569 13 709 46 fade-trail? fade-trail? 1 1 -1000 TEXTBOX 602 239 794 263 (force lasts for 1/10 of a second) SWITCH 448 12 551 45 count? count? 0 1 -1000 @#$#@#$#@ @#$#@#$#@ default true 0 Polygon -7500403 true true 150 5 40 250 150 205 260 250 link true 0 Line -7500403 true 150 0 150 300 link direction true 0 Line -7500403 true 150 150 30 225 Line -7500403 true 150 150 270 225 arrow true 0 Polygon -7500403 true true 150 33 30 108 Polygon -7500403 true true 270 109 151 29 Polygon -7500403 true true 32 111 151 26 268 109 Rectangle -7500403 true true 88 101 219 221 arrow-2 true 0 Polygon -7500403 true true 150 33 30 108 Polygon -7500403 true true 270 109 151 29 Rectangle -7500403 true true 75 101 96 230 Rectangle -7500403 true true 76 214 221 231 Rectangle -7500403 true true 200 102 220 230 Polygon -7500403 true true 151 17 149 46 221 105 251 104 Polygon -7500403 true true 151 19 42 102 77 103 150 48 150 47 Polygon -7500403 true true 70 91 87 120 23 118 45 102 Polygon -7500403 true true 218 107 213 126 270 123 246 100 bagel false 0 Polygon -6459832 true false 81 28 145 12 216 27 259 80 277 154 265 220 215 262 151 283 79 273 21 222 7 155 29 80 88 128 86 173 116 211 180 199 196 164 189 125 157 104 112 100 Polygon -6459832 true false 83 31 45 58 31 82 84 132 119 89 ball true 0 Circle -16777216 true false 30 31 243 Circle -1 true false 128 62 27 Circle -1 true false 173 71 30 Circle -1 true false 122 120 32 bug true 0 Circle -16777216 true false 92 35 118 Circle -2674135 true false 48 70 206 Polygon -16777216 true false 146 69 129 277 174 279 Circle -16777216 true false 85 109 43 Circle -16777216 true false 173 111 37 Circle -16777216 true false 198 164 40 Circle -16777216 true false 182 221 27 Circle -16777216 true false 67 167 43 Circle -16777216 true false 96 228 24 cookie false 0 Circle -6459832 true false 30 31 243 Circle -1 true false 57 59 189 Circle -11221820 true false 115 109 14 Circle -11221820 true false 173 207 23 Circle -11221820 true false 190 146 15 Circle -8630108 true false 150 74 16 Circle -8630108 true false 136 166 14 Circle -8630108 true false 70 134 24 Circle -13840069 true false 127 202 19 Circle -13840069 true false 187 98 17 Circle -955883 true false 94 189 13 Circle -955883 true false 151 124 18 Circle -955883 true false 210 185 12 Circle -2064490 true false 165 182 21 Circle -2064490 true false 219 123 9 Circle -2064490 true false 113 80 17 Circle -10899396 true false 115 135 15 cookie-3 true 0 Circle -6459832 true false 30 31 243 Circle -1 true false 88 86 138 Circle -1 true false 81 169 78 Circle -1 true false 139 119 109 Circle -1 true false 124 64 92 Circle -1 true false 85 65 111 Circle -1 true false 54 83 135 Circle -1 true false 87 111 135 Circle -5825686 true false 125 109 22 Circle -5825686 true false 201 170 21 Circle -13345367 true false 106 190 26 Circle -13345367 true false 167 84 27 Circle -13840069 true false 63 125 18 Circle -13840069 true false 173 191 28 Circle -13840069 true false 165 130 24 Circle -955883 true false 83 153 25 Circle -955883 true false 138 219 20 Circle -8630108 true false 136 159 21 Circle -8630108 true false 96 97 16 Circle -8630108 true false 213 134 16 donut false 0 Polygon -6459832 true false 81 28 145 12 216 27 259 80 277 154 265 220 215 262 151 283 79 273 21 222 7 155 29 80 88 128 86 173 116 211 180 199 196 164 189 125 157 104 112 100 Polygon -6459832 true false 83 31 45 58 31 82 84 132 119 89 Polygon -1 true false 63 61 37 127 30 187 59 235 108 261 182 256 242 210 256 151 222 62 171 39 101 43 120 80 177 83 210 115 215 169 194 210 138 229 95 222 73 185 76 124 104 85 85 53 Polygon -1 true false 80 56 101 44 119 80 100 82 Circle -11221820 true false 60 65 17 Circle -11221820 true false 152 60 16 Circle -11221820 true false 231 141 16 Circle -11221820 true false 179 228 14 Circle -5825686 true false 120 48 14 Circle -5825686 true false 215 96 12 Circle -5825686 true false 56 185 16 Circle -13840069 true false 54 105 13 Circle -13840069 true false 132 250 19 Circle -13840069 true false 194 64 14 Circle -1184463 true false 81 61 16 Circle -1184463 true false 203 195 16 Circle -1184463 true false 78 225 18 Circle -8630108 true false 26 169 21 Circle -8630108 true false 232 164 16 Circle -955883 true false 138 221 24 Circle -955883 true false 52 129 19 Circle -13345367 true false 157 38 20 Circle -13345367 true false 227 197 13 donut-3 false 0 Circle -6459832 true false 37 37 231 Circle -16777216 true false 112 109 86 Circle -1 true false 67 80 34 Circle -1 true false 47 127 51 Circle -1 true false 80 185 38 Circle -1 true false 99 210 41 Circle -1 true false 134 220 22 Circle -1 true false 54 169 34 Circle -1 true false 53 101 30 Circle -1 true false 93 56 35 Circle -1 true false 110 61 37 Circle -1 true false 143 61 31 Circle -1 true false 168 65 35 Circle -1 true false 194 75 31 Circle -1 true false 213 125 18 Circle -1 true false 198 89 36 Circle -1 true false 221 134 37 Circle -1 true false 199 160 39 Circle -1 true false 192 195 44 Circle -1 true false 174 212 24 Circle -1 true false 146 213 38 Circle -2064490 true false 125 78 9 Circle -2064490 true false 205 102 10 Circle -2064490 true false 213 206 8 Circle -2064490 true false 63 181 4 Circle -2064490 true false 50 141 15 Circle -2064490 true false 115 221 23 Circle -1184463 true false 75 89 16 Circle -1184463 true false 167 68 13 Circle -1184463 true false 217 169 18 Circle -1184463 true false 83 196 14 Circle -1184463 true false 175 220 13 Circle -13840069 true false 65 124 16 Circle -13840069 true false 149 71 11 Circle -13840069 true false 189 79 12 Circle -13840069 true false 227 132 12 Circle -13840069 true false 193 212 14 Circle -13840069 true false 106 209 11 Circle -13345367 true false 95 73 9 Circle -13345367 true false 210 85 8 Circle -13345367 true false 71 157 11 Circle -13345367 true false 149 234 13 Circle -13345367 true false 226 151 10 fire true 0 Rectangle -7500403 true true 92 82 207 249 Polygon -7500403 true true 151 27 111 47 93 82 205 84 189 43 rocket true 0 Polygon -7500403 true true 152 17 69 88 229 89 Rectangle -7500403 true true 70 105 228 231 Rectangle -7500403 true true 174 248 226 274 Rectangle -7500403 true true 72 249 125 275 rocket3 true 0 Polygon -7500403 true true 150 9 106 43 87 88 213 89 198 43 Rectangle -7500403 true true 89 101 211 238 Rectangle -7500403 true true 223 103 253 213 Rectangle -7500403 true true 50 107 82 209 Rectangle -2674135 true false 220 188 256 217 Rectangle -13345367 true false 49 107 85 133 @#$#@#$#@ NetLogo 3.1.5 @#$#@#$#@ @#$#@#$#@ @#$#@#$#@ @#$#@#$#@