|
|
|
globals [ speeds fuel_remaining acceleration particle_left running? maxint time force-scale-constant collision-radius random-unit positive-magnitude negative-magnitude charge-patches field-patches electron-mass ion-mass ion-magnitude electron-magnitude ]
turtles-own [ magnitude mass speed ]
breed [workers worker] breed [ions ion] breed [electrons electron] breed [jets jet] breed [charges charge]
patches-own [ field-charge-magnitude field-strength field-direction ]
to setup clear-all ;This will clear everything from the model import-pcolors "ion-propulsion.png" ;This sets the patches to their colors set-globals ; this will set all the globals to their default numbers set-charges ;this will give the build-field command patches to perform it on build-field ;This calculates the direction and strength of the magnetic force end
to set-charges set charge-patches (patches with [shade-of? pcolor blue]); this sets the charge-patches to every patch wit a color that is a shade of blue ask charge-patches [ set field-charge-magnitude negative-magnitude ; sets the magnitude of the patches ] end
to build-field set field-patches (patches with [pcolor = black and pycor > 9 ]) ask field-patches [ ;asks the field patches to compute the force on them compute-force ] end
to compute-force let x pxcor let y pycor let sum-x (sum [field-charge-magnitude * sin (towards myself) / ((distance myself) ^ 2)] of charge-patches) let sum-y (sum [field-charge-magnitude * cos (towards myself) / ((distance myself) ^ 2)] of charge-patches) set field-strength (sqrt (sum-x ^ 2 + sum-y ^ 2)) ;When these computations are finished, the turtle will tell the patch it's force strength set field-direction (atan sum-x sum-y) ;and direction end
to go tick inject ask turtles [ move ] end
to set-globals ; This set the global variables in the model set fuel_remaining 100 set particle_left 0 set speeds 0 set acceleration 0
;; CHANGE THESE BOGUS NUMBERS!!!! set force-scale-constant 0.003 set positive-magnitude 50 set negative-magnitude -50 set electron-mass 1 set ion-mass 1000 set electron-magnitude -.5 set ion-magnitude 0 set collision-radius 0.1 end
to remove-fuel create-workers 1 ask workers [setxy 0 40] ask workers [evaluate-row-and-move]
end to evaluate-row-and-move repeat 23 [ let row-patches patches-in-this-row ifelse (all? row-patches [pcolor = black]) [ set heading 180 ifelse (can-move? 1) [ forward 1 ] [ set running? false ] ] [ let color-patches row-patches with [pcolor != black] let target (min-one-of color-patches [distance myself]) face target kill-row ]] end
to-report patches-in-this-row let base-x-offset (min-pxcor - pxcor) let patch-list (n-values world-width [patch-at (base-x-offset + ?) 0]) report (patch-set patch-list) end
to kill-row ask workers [ repeat 5 [ if (pcolor != black) [ set pcolor black ] set heading 90 fd 1]set fuel_remaining (fuel_remaining - (100 / 25) ) die] end
to move if (xcor < (-0.5 + min-pxcor + 5)) [ die ] ifelse (pcolor = black) [ let new-x (speed * sin heading + (magnitude * field-strength * force-scale-constant * sin field-direction) / mass) let new-y (speed * cos heading + (magnitude * field-strength * force-scale-constant * cos field-direction) / mass) ; show (list new-x new-y) set speed (sqrt (new-x ^ 2 + new-y ^ 2)) set heading (atan new-x new-y) ] [ ; if ((pcolor = blue or pcolor = yellow) and breed = ions or breed = electrons) [ ; set particle_left (particle_left + 1) ] ifelse (can-move? speed) [ forward speed if (breed = ions and magnitude < 8) [ check-collision ] ] [ set particle_left (particle_left + 1) die ] end
to inject ; DO ELECTRONS if (remainder ticks 50 = 0 and fuel_remaining > 0) [ create-ions 10 [ setup-ion ]] if (remainder ticks 15 = 0) [ create-electrons 200 [ setup-electron ] ] end
to setup-ion let x1 (-0.5 + min-pxcor + 5 + random-float (world-width - 5)) let x2 (-0.5 + min-pxcor + 5 + random-float (world-width - 5)) setxy ((x1 + x2) / 2) max-pycor set shape "circle" set size 1 set color 28 set heading 180 set magnitude ion-magnitude set mass ion-mass set speed .1 end
to setup-electron ; Probably don't need this for electrons let x1 (-0.5 + min-pxcor + 5 + random-float (world-width - 5)) let x2 (-0.5 + min-pxcor + 5 + random-float (world-width - 5)) setxy ((x1 + x2) / 2) max-pycor set shape "circle" set size .5 set color blue set heading 180 set magnitude electron-magnitude set mass electron-mass set speed .5 end
to check-collision let collidees (electrons in-radius collision-radius) if (any? collidees) [ ask one-of collidees [ collide ] set magnitude magnitude + 1 set color red + 4.5 - magnitude ] end
to collide let old-x speed * sin heading let old-y speed * cos heading let new-electron-heading heading - 90 + (180 * random-unit) let new-x sin heading - 0.5 * sin new-electron-heading let new-y cos heading - 0.5 * cos new-electron-heading set speed (speed / 2) set heading atan new-x new-y hatch 1 [ set heading new-electron-heading ] end
to collide-surface end
|
|
Questions/Concerns Contact the
Webmaster Home | Compare | Photos | Final Report |