Weird Landscapes

Shaping a Landscape

Patches have pre-defined attributes: pcolor, plabel, pxcor, pycor. We can also define new attributes. For example, here is how we could define an altitude attribute for all patches:

patches-own [altitude]

Of course we need to set the altitude for different patches:

ask patches [set-altitude]

For this to work we need to define a set-altitude procedure. If we think of turtle world as a landscape, then the altitude of a patch will depend on its location. For example, suppose the altitude of a patch was simply the sum the square of it's x and y coordinates.

to set-altitude
  set altitude pxcor * pxcor + pycor * pycor
end

Representing Colors in NetLogo

In NetLogo colors are represented by numbers from 0 to 140:

We can use a color name to set the color of a patch or turtle:

ask patches [set pcolor red]
ask turtles [set color green]

There are two useful ways to map a number like altitude into a color number in the range 0 to 140:

set pcolor wrap-color altitude

set pcolor scale-color blue altitude lowest-altitude highest-altitude

You can read about these procedures in the NetLogo Dictionary (under the Help menu).

Coloring a Landscape

We can use color to make the altitude of a patch visible:

ask patches [set-pcolor]

The color of a patch depends on its altitude. There are two ways to do this: scaling and wrapping. For example, suppose the altitude of a patch was represented by a shade of green:

to set-pcolor
   set pcolor scale-color green altitude 0 256
end

Higher altitudes are lighter shades of green. The lowest patches, those near the center, form a dark pit:

 

Instead we can try using the wrap-color method:

to set-pcolor
   set pcolor wrap-color altitude
end

Now our landscape resembles a Navajo blanket:

Thus, different colors represent different altitudes in some weird landscape shaped by valleys, hills, cliffs, wells, and peaks.

Canyon

Cliff

Saddle Point

Psychedelic

Why are weird landscapes interesting?

Imagine if we replace altitude by temperature, rain fall, or crime rate.

Imagine if the coordinates of a patch represented age and income of a population and altitude represented government approval rating.

Imagine if the coordinates of a patch represented risk and return of a portfolio of investments and the altitude represented amount invested.

Labs

1. Altitude as a function of patch position

Every patch in a landscape has the following attributes:

patches-own [altitude temperature wealth risk density charge]

Here's a screen-shot of the landscapes.nlogo:

The attribute chooser selects which patch attribute will determine the color of the patch.

The technique chooser determines if patches will be colored using the scale-color or wrap-color procedure.

Clicking the init-patches button calls the init-patches procedure:

to init-patches
   ask patches [init-patch]
end

This procedure asks each patch to execute the init-patch procedure:

to init-patch
   set altitude ...
  set temperature ...
   set-risk ...
  ; etc.
   set-color
end

The set-color procedure is a series of conditionals of the form:

if attribute = "altitude"
[ifelse technique = "shade"
   [set pcolor ...]
   [set pcolor ...]
]

The value of every patch attribute is a function of its position. In other words, the value is determined by a formula involving pxcor and pycor.

Here are the formulas in word form:

The altitude of a patch is 256' less the product of its coordinates. What is the maximum altitude of a patch? What is the minimum altitude?

The temperature of a patch is 256 degrees less the sum of the squares of its coordinates. What is the maximum altitemperature of a patch? What is the minimum temperature?

The wealth of a patch is $256 less the sum of its coordinates. What is the maximum wealth of a patch? What is the minimum wealth?

The risk of a patch is a random number less than 140.

The density of a patch is 1 if the product of its coordinates is odd, 0 if even. (Hint: use the remainer function for this.)

The charge of a patch is 12 times the sin of 18 times its x coordinate = 12 * sin(18 * x)

2. Altitude as a function of distance from a patch

Every patch in a landscape has the following attributes:

patches-own [supply demand price influence stability]

Create a netlogo program called economy. This is similar to the landscapes program above in that users can select an attribute and a technique, then initialize the attributes according to the following "formulas":

The supply of some product at a patch P increases according to P's distance from patch 10 10

the demand for some product at a patch P increases the closer P is to the center

the price of a product at a patch P is average of P's distances to 10 10 and 0 0

the influence of an ad campaign at a patch P is its nearness to the center point of its quadrant. (There are four quadrants: I, II, III, and IV:

 

the stability of the price of a product at a patch is its distance from the closest patch with pycor = -10.

Hint: use the distancexy procedure.

3. Seascapes

Like a landscape, every patch of the ocean's surface has an altitude (or depth). Unlike a landscape, the altitude of a patch constantly changes as waves lift and drop the patch.

In this lab you will create a rolling seascape:

Dark green patches have a fixed minimum depth of 240 feet.

Light green patches are deeper depending on how close they are to the crest of the wave.

White patches are at the crest of the wave. They have depth 256 feet.

The seascape program has a global variable called crest:

globals [crest]

The value of crest is the pycor located at the top of the wave.

Every patch has a depth attribute:

patches-own [depth]

Clicking the init-patches button calls the init-patches procedure:

to init-patches
   set crest min-pycor
   ask patches [update-patch]
end

The update-patch procedure calculates the distance of the executing patch to the nearest patch on the crest. If this distance is less than 10, then the depth of the patch is the maximum depth (256 feet) minus the distance. Otherwise the depth is the minimum depth (240 feet). The update-patch procedure than calls the scale-color procedure to set the pcolor of the patch.

Clicking the roll button repeatedly calls the roll procedure. This procedure increments crest by 1. If crest is beyond max-pycor, then it is reset to min-pycor. Next, all patches are asked to update themselves.