Erosion+Code+Modified


 * < Erosion <

globals [ show-water? ;; whether the water is visible clock ;; how many simulation steps have passed drains ;; agentset of all edge patches where the water drains off land ;; agentset of all non-edge patches ]
 * hill1x**
 * hill1y**
 * hill2x**
 * hill2y**
 * hill3x**
 * hill3y**
 * hill4x**
 * hill4y**
 * hill5x**
 * hill5y**

patches-own [ elevation ;; elevation here (may be negative) water ;; depth of water here drain? ;; is this an edge patch? ]

to setup clear-all
 * set hill1x -50**
 * set hill1y 50**
 * set hill2x 50**
 * set hill2y 50**
 * set hill3x 50**
 * set hill3y -50**
 * set hill4x -50**
 * set hill4y -50**
 * set hill5x 0**
 * set hill5y 0**

set show-water? true set clock 0 ask patches [ ifelse bumpy? [ ifelse hill? [ set elevation -100 * (


 * (sqrt sqrt (distancexy hill1x hill1y)**
 * - sqrt (distancexy hill2x hill2y)**
 * + sqrt (distancexy hill3x hill3y)**
 * - sqrt sqrt (distancexy hill4x hill4y)**
 * - sqrt (distancexy hill5x hill5y)**

) / (sqrt sqrt max-pxcor) )

+ random 100 ]

[ set elevation random 125 ] ] [ set elevation 100 ] set water 0 set drain? false ] if bumpy? [ repeat terrain-smoothness [ diffuse elevation 0.5 ] ] ask patches with [count neighbors != 8] [ set drain? true set elevation -10000000 ] set drains patches with [drain?] set land patches with [not drain?] ask land [ recolor ] end
 * the DIFFUSE command is useful for smoothing out the terrain
 * make the drain around the edge
 * display the terrain

to recolor ;; patch procedure ifelse water = 0 or not show-water? [ set pcolor scale-color white elevation -250 100 ] [ set pcolor scale-color blue (min list water 75) 100 -10 ] end

to show-water set show-water? true ask land [ recolor ] end

to hide-water set show-water? false ask land [ recolor ] end

to go no-display ask land [ if random-float 1.0 < rainfall [ set water water + 1 ] ] ask land [ without-interruption [ ;; make sure patches go one at a time if water > 0 [ flow ] ] ]
 * we use no-display and display to make the simulation run faster
 * first do rainfall
 * then do flow; we don't want to bias the flow in any
 * particular direction, so we need to shuffle the execution
 * order of the patches each time; using an agentset does
 * this automatically.

ask drains [ set water 0 set elevation -10000000 ] ask land [ recolor ] set clock clock + 1 display
 * reset the drains to their initial state
 * update the patch colors
 * update the clock
 * turn the display back on


 * if clock = 500 [ stop ]

end

to flow ;; patch procedure let target min-one-of neighbors [elevation + water] let amount min list water (0.5 * (elevation + water - elevation-of target - water-of target)) if amount > 0 [ let erosion amount * (1 - soil-hardness) set elevation elevation - erosion set amount min list water (0.5 * (elevation + water - elevation-of target - water-of target)) set water water - amount set (water-of target) (water-of target) + amount ] end
 * find the neighboring patch where the water is lowest
 * the amount of flow is half the level difference, unless
 * that much water isn't available
 * don't flow unless the water is higher here
 * first erode
 * but now the erosion has changed the amount of flow needed to equalize the level,
 * so we have to recalculate the flow amount


 * *** NetLogo 3.1.3 Model Copyright Notice ***
 * This model was created as part of the projects:
 * PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN
 * CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT.
 * The project gratefully acknowledges the support of the
 * National Science Foundation (REPP & ROLE programs) --
 * grant numbers REC #9814682 and REC-0126227.
 * Copyright 2004 by Uri Wilensky. All rights reserved.
 * Permission to use, modify or redistribute this model is hereby granted,
 * provided that both of the following requirements are followed:
 * a) this copyright notice is included.
 * b) this model will not be redistributed for profit without permission
 * from Uri Wilensky.
 * Contact Uri Wilensky for appropriate licenses for redistribution for
 * profit.
 * To refer to this model in academic publications, please use:
 * Wilensky, U. (2004). NetLogo Erosion model.
 * http://ccl.northwestern.edu/netlogo/models/Erosion.
 * Center for Connected Learning and Computer-Based Modeling,
 * Northwestern University, Evanston, IL.
 * In other publications, please use:
 * Copyright 2004 Uri Wilensky. All rights reserved.
 * See http://ccl.northwestern.edu/netlogo/models/Erosion
 * for terms of use.
 * *** End of NetLogo 3.1.3 Model Copyright Notice ***
 * In other publications, please use:
 * Copyright 2004 Uri Wilensky. All rights reserved.
 * See http://ccl.northwestern.edu/netlogo/models/Erosion
 * for terms of use.
 * *** End of NetLogo 3.1.3 Model Copyright Notice ***
 * *** End of NetLogo 3.1.3 Model Copyright Notice ***


 * <erosion<