Created
August 3, 2017 17:00
-
-
Save TheBizzle/f879c6027c50122eab58cfb6cbbb3362 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <html> | |
| <head> | |
| <link rel="stylesheet" media="screen" href= "http://netlogoweb.org/assets/lib/codemirror/lib/codemirror.css"> | |
| <link rel="stylesheet" media="screen" href= "http://netlogoweb.org/assets/stylesheets/netlogo-syntax.css"> | |
| <script src="http://netlogoweb.org/assets/lib/codemirror/lib/codemirror.js"></script> | |
| <script src="http://netlogoweb.org/assets/lib/codemirror/addon/mode/simple.js"></script> | |
| <script src="http://netlogoweb.org/assets/javascripts/codemirror/mode.js"></script> | |
| </head> | |
| <div id="nl-code" style="height: 700px;">breed [ rockets rocket ] | |
| breed [ frags frag ] | |
| globals [ | |
| countdown ; how many ticks to wait before a new salvo of fireworks | |
| ] | |
| turtles-own [ | |
| col ; sets color of an explosion particle | |
| x-vel ; x-velocity | |
| y-vel ; y-velocity | |
| ] | |
| rockets-own [ | |
| terminal-y-vel ; velocity at which rocket will explode | |
| ] | |
| frags-own [ | |
| dim ; used for fading particles | |
| ] | |
| to setup | |
| clear-all | |
| set-default-shape turtles "circle" | |
| reset-ticks | |
| end | |
| ; This procedure executes the model. If there are no turtles, | |
| ; it will either initiate a new salvo of fireworks by calling | |
| ; INIT-ROCKETS or continue to count down if it hasn't reached 0. | |
| ; It then calls PROJECTILE-MOTION, which launches and explodes | |
| ; any currently existing fireworks. | |
| to go | |
| if not any? turtles [ | |
| ifelse countdown = 0 [ | |
| init-rockets | |
| ; use a higher countdown to get a longer pause when trails are drawn | |
| set countdown ifelse-value trails? [ 30 ] [ 10 ] | |
| ] [ | |
| ; count down before launching a new salvo | |
| set countdown countdown - 1 | |
| ] | |
| ] | |
| ask turtles [ projectile-motion ] | |
| tick | |
| end | |
| ; This procedure creates a random number of rockets according to the | |
| ; slider FIREWORKS and sets all the initial values for each firework. | |
| to init-rockets | |
| clear-drawing | |
| create-rockets (random fireworks) [ | |
| setxy random-xcor min-pycor | |
| set x-vel ((random-float (2 * initial-x-vel)) - (initial-x-vel)) | |
| set y-vel ((random-float initial-y-vel) + initial-y-vel * 2) | |
| set col one-of base-colors | |
| set color (col + 2) | |
| set size 2 | |
| set terminal-y-vel (random-float 4.0) ; at what speed does the rocket explode? | |
| ] | |
| end | |
| ; This function simulates the actual free-fall motion of the turtles. | |
| ; If a turtle is a rocket it checks if it has slowed down enough to explode. | |
| to projectile-motion ; turtle procedure | |
| set y-vel (y-vel - (gravity / 5)) | |
| set heading (atan x-vel y-vel) | |
| let move-amount (sqrt ((x-vel ^ 2) + (y-vel ^ 2))) | |
| if not can-move? move-amount [ die ] | |
| fd (sqrt ((x-vel ^ 2) + (y-vel ^ 2))) | |
| ifelse (breed = rockets) [ | |
| if (y-vel < terminal-y-vel) [ | |
| explode | |
| die | |
| ] | |
| ] [ | |
| fade | |
| ] | |
| end | |
| ; This is where the explosion is created. | |
| ; EXPLODE calls hatch a number of times indicated by the slider FRAGMENTS. | |
| to explode ; turtle procedure | |
| hatch-frags fragments [ | |
| set dim 0 | |
| rt random 360 | |
| set size 1 | |
| set x-vel (x-vel * .5 + dx + (random-float 2.0) - 1) | |
| set y-vel (y-vel * .3 + dy + (random-float 2.0) - 1) | |
| ifelse trails? | |
| [ pen-down ] | |
| [ pen-up ] | |
| ] | |
| end | |
| ; This function changes the color of a frag. | |
| ; Each frag fades its color by an amount proportional to FADE-AMOUNT. | |
| to fade ; frag procedure | |
| set dim dim - (fade-amount / 10) | |
| set color scale-color col dim -5 .5 | |
| if (color < (col - 3.5)) [ die ] | |
| end | |
| ; Copyright 1998 Uri Wilensky. | |
| ; See Info tab for full copyright and license. | |
| </div> | |
| <script> | |
| var elem = document.getElementById("nl-code"); | |
| var text = elem.textContent; | |
| elem.innerHTML = ""; | |
| CodeMirror(elem, { | |
| mode: 'netlogo' | |
| , readOnly: true | |
| , theme: 'netlogo-default' | |
| , value: text | |
| , viewportMargin: Infinity | |
| }); | |
| elem.querySelector(".CodeMirror").style.height = "700px"; | |
| </script> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment