Ralph Abraham's course webpage
;;; arabesque.nlogo, cr 16 apr 2006 by rha on hypatia
;;; imitate john whitney sr pascal code
globals [ mylist ] ;;;;defining a global variable of type "list" (added 1-15)
;;;;;;origin point= center
:::::window is 35 patches square, and 1 patch=12 pixels.
::::turtle shapes and ticker counter are checked
;;;;;;there are three buttons: setup, step, and go:
to setup ;;;;defining the setup button's functions
ca ;;;clear all
set mylist n-values 360 [?] ;;;;give a numerical value of 360 to the turtles
crt 360 ;;;;create 360 turtles
foreach mylist [ ;;;;runs the same command for the whole set
ask turtle ? [ ;;;; all turtles run the following group of commands
set color red ;;;all turtles are red
set heading ? ;;;; all the turtles face a certain direction.This is defined later, in step, and I am not sure what the ? does here. does it refer to all the turtles?
forward 15 ;;;;the turtle moves forward 15 steps. Do steps = pixels or patches?
] ;;;close second set of commands, defining turtles
] ;;;;close first set of commands, defining list items
end ;;;stop defining setup button commands
to step ;;;;defining the step button's functions
let stepsize 0.01 ;;;;defines step size as .01 (patches? The step button appears to move everything forward more than .01 of a patch.?)
foreach mylist [ ;;;runs the same command for the whole set
ask turtle ? [ ;;; all turtles run the following group of commands
set heading 90 ;;;;;turtles face 90 degrees, right/east
forward ? * stepsize ;;;;turtles move forward 0.01
];;;close second set of commands, defining turtles
] ;;;;close first set of commands, defining list items
end ;;;stop defining step button commands
to go ;;;;defining the go button's functions
step ;;;when the go button is active, the turtles execute the step command
end ;;;stop defining go button commands
;;; end: arabesque
I would like to create a dynamic representation of chocolate production and consumption around the world, inspired by some of the swarming models shown in, for example, the Wolf-Sheep Predation model. I'm interested in representing where chocolate flows, from its origin to its processing to its consumption.
I could use a map of the world to anchor this data, which would eventually be obscured by chocolate swarms. I'm not sure what the end result of the model would be, because if there wasn't some sort of digestion of the consumed chocolate it will just pile up. This might be desirable, depending on how the piles look/what they do.
I have a feeling this might be too advanced for what I know having participated in unit one (the map is certainly too advanced). Maybe I can focus on just doing one single part of this swarming network, like where does chocolate grown in Ghana go for production (probably the US or Netherlands) and where does the processed chocolate go from there. Or maybe I could make a bunch of turtles swarm from one place to another, and call it a day.
World of Chocolate
(Some of the lines are so similar to other lines I didn't comment on each line.)
and a direct link to the netlogo file
the model without comments
;;;comments on ben's porter class model, lindsay kelley, january 27 2008
extensions [ sound ] ;;;allow sound
breed [fly flies] ;;;create breed of turtles
globals [ new-u lr ] ;;;define variables new-u and lr
fly-own [direction colorv direction-c] ;;;the breed of turtles created above own their direction & color (I'm not sure what "direction-c" means-- it doesn't appear anywhere else in the model?)
to setup ;;set up model
ca ;;clear all
create-fly 15 ;;create 15 flies
[ set colorv random 139 ;;set colors to be random
set direction random 360 ;;set direction to be random, all angles are possible
set shape "firefly" ;;; custom designed turtle
set color colorv ;;set random color
setxy (random xcor)(random ycor) ;;set random x and y coordinates
set size random 4 + 3 ;;; allows some size variation
set heading direction ;;Set heading (refers to random direction above)
set new-u 0.5 ;;; initial point of the trajectory
]
ask (patch 17 -17) [ set pcolor yellow ] ;;define colors for the patches at the edges of the graphics window
ask (patch -17 -17) [ set pcolor blue ]
ask (patch 17 17) [ set pcolor green ]
ask (patch -17 17) [set pcolor red]
ask (patch 0 17) [set pcolor orange]
ask (patch -17 0) [set pcolor pink]
ask (patch 0 -17) [set pcolor lime]
ask (patch 17 0) [set pcolor sky]
adjust-turtles ;;run adjust turtles command
end
to adjust-turtles ;;adjust turtles command
ask turtle 0 [ ;;ask one turtle to be big and yellow
set size 5
set color yellow
]
end
to go ;;define go
set new-u logistic r-param new-u ;;run the logistic function once
ask turtles ;;ask turtles to move forward, rotating right or left depending on if lr variable is 1 or other number.
[fd 1
set lr random 2
ifelse lr = 1 [ rt new-u * 15]
[lt new-u * 15]
if (count other turtles-here > 0 ) [set color random 130 + 9] ;;if there are turtles, their color will be random
if ( [pcolor] of patch-here = green ) [magic] ;;If the turtles touch one of the colored patches, various sound functions will happen
if ( [pcolor] of patch-here = blue ) [blast]
if ( [pcolor] of patch-here = red ) [dream]
if ( [pcolor] of patch-here = yellow) [live]
if ( [pcolor] of patch-here = orange) [breathe]
if ( [pcolor] of patch-here = pink) [weep]
if ( [pcolor] of patch-here = sky) [walk]
if ( [pcolor] of patch-here = lime) [dance]
]
end
to magic ;;If the turtle hits a green patch, a short sound will play after waiting 0.5 seconds
let beat 0.5
sound:play-note-later 0 * beat "Halo" 51 50 beat / 1
end
to blast ;;If the turtle hits a blue patch, a short sound will play after waiting 0.5 seconds
let beat 0.5
sound:play-note-later 0 * beat "Halo" 53 50 beat / 1
end
to dream ;;If the turtle hits a red patch, a short sound will play after waiting 0.5 seconds
let beat 0.5
sound:play-note-later 0 * beat "Halo" 55 50 beat / 1
end
to live ;;If the turtle hits a yellow patch, a short sound will play after waiting 0.5 seconds
let beat 0.5
sound:play-note-later 0 * beat "Halo" 56 50 beat / 1
end
to breathe ;;If the turtle hits a orange patch, a short sound will play after waiting 0.5 seconds
let beat 0.5
sound:play-note-later 0 * beat "Halo" 58 50 beat / 1
end
to weep ;;If the turtle hits a pink patch, a short sound will play after waiting 0.5 seconds
let beat 0.5
sound:play-note-later 0 * beat "Halo" 60 50 beat / 1
end
to dance ;;If the turtle hits a lime patch, a short sound will play after waiting 0.5 seconds
let beat 0.5
sound:play-note-later 0 * beat "Halo" 62 50 beat / 1
end
to walk ;;If the turtle hits a sky patch, a short sound will play after waiting 0.5 seconds
let beat 0.5
sound:play-note-later 0 * beat "Halo" 63 50 beat / 1
end
;;; ==============================================
;;; the logistic function: f(R, u) = Ru(1-u)
to-report logistic [ are you ]
report are * you * ( 1 - you )
end
The model requires a .wav file and a .gif file, both of which plus the model itself may be found here:
http://danm.ucsc.edu/~lkelley/nlogo/final/
The model itself:
;;;;chocolate.nlogo January 15 2008 lindsay kelley
globals [ mylist ] ;;;I'm still not sure about this line, but getting rid of it gives an error. :/
breed [cotedivoires cotedivoire] ;;;;create cote d'ivoire breed
breed [ghanas ghana] ;;;;create ghana breed
breed [indonesias indonesia] ;;;;create indonesia breed
turtles-own [energy] ;;trying to allow the chocolate to be eaten by giving it energy variable
extensions [ sound ] ;;enable sound
to start ;;;;initialize the model
ca ;;;clear all
import-drawing "world.gif" ;;import background image of the world
ask patches ;;;;create random background--leaving this in just in case the image doesn't load for some reason.
[ set pcolor 31 + (random-float 0.8) - 0.4] ;; varying the brown
set-default-shape cotedivoires "square" ;;;set turtles to be square shaped
set-default-shape ghanas "square" ;;;set turtles to be square shaped
set-default-shape indonesias "square" ;;;set turtles to be square shaped
create-cotedivoires 13 [ ;;;create turtles
set pen-size 3 ;;;;set pen size
set color 33 ;;;;set color
set energy (5) ;;;;set energy
setxy 0 -16 ;;move turtles to a less conspicuous place for loading
]
create-ghanas 7 [ ;;;create turtles
set pen-size 3 ;;;;set pen size
set color 31 ;;;;set color
set energy (5) ;;;;set energy
setxy 0 -15 ;;move turtles to a less conspicuous place for loading
]
create-indonesias 4 [ ;;;create turtles
set pen-size 3 ;;;;set pen size
set color 32 ;;;;set color
set energy (5) ;;;;set energy
setxy 0 -14 ;;move turtles to a less conspicuous place for loading
]
end
to setup ;;;place cote d'ivoire squares & start plot
do-plots
ask cotedivoire 0 [ ;;;assigns different coordinates to each square
setxy 0 2]
ask cotedivoire 1 [
setxy 0 1]
ask cotedivoire 2 [
setxy 0 3]
ask cotedivoire 3 [
setxy -1 1]
ask cotedivoire 4 [
setxy -1 2]
ask cotedivoire 5 [
setxy -1 3]
ask cotedivoire 6 [
setxy -2 1]
ask cotedivoire 7 [
setxy -2 2]
ask cotedivoire 8 [
setxy -2 3]
ask cotedivoire 9 [
setxy -3 1]
ask cotedivoire 10 [
setxy -3 2]
ask cotedivoire 11 [
setxy -3 3]
ask cotedivoire 12 [
setxy -4 1]
end
to setup2 ;;;place ghana squares
ask ghana 13 [ ;;;assigns different coordinates to each square
setxy 1 2]
ask ghana 14 [
setxy 2 2]
ask ghana 15 [
setxy 3 2]
ask ghana 16 [
setxy 4 2]
ask ghana 17 [
setxy 5 2]
ask ghana 18 [
setxy 1 3]
ask ghana 19 [
setxy 2 3]
end
to setup3 ;;;place indonesia squares
ask indonesia 20 [ ;;;assigns different coordinates to each square
setxy 15 0]
ask indonesia 21 [
setxy 16 0]
ask indonesia 22 [
setxy 17 0]
ask indonesia 23 [
setxy 18 0]
end
to cotedivoire-netherlands ;;;;move cote d'ivoire turtles to "netherlands" xy coordinate (0 0)
ask cotedivoires ;;;draw a line between original location and Netherlands location
[
pd ;;;pen down so the turtle draws a line
setxy 1 10 ] ;;set x y
end
to ghana-netherlands;;;;move ghana turtles to "netherlands" xy coordinate (0 0)
ask ghanas;;;draw a line between original location and Netherlands location
[
pd ;;;pen down so the turtle draws a line
setxy 1 10 ] ;;set x y
end
to indonesia-netherlands ;;;;move indonesia turtles to "netherlands" xy coordinate (0 0)
ask indonesias ;;;draw a line between original location and Netherlands location
[
pd ;;;pen down so the turtledraws a line
setxy 1 10 ] ;;set x y
end
to process ;;;process chocolate
cotedivoire-netherlands ;;;run move turtles commands
ghana-netherlands
indonesia-netherlands
end
to sendBelgium ;;;send processed chocolate to Belgium
ask cotedivoire 0 [ ;;;arrange processed chocolate in rows
set color red
setxy 0 11]
ask cotedivoire 1 [
set color red
setxy -1 11]
ask cotedivoire 2 [
set color red
setxy -2 11]
ask cotedivoire 3 [
set color red
setxy -3 11]
ask ghana 13 [
set color 14
setxy 0 10]
ask ghana 14 [
set color 14
setxy -1 10]
ask indonesia 20 [
set color 13
setxy -2 10]
sound:play-sound "Chewing.wav" ;;chewing sound by The University of Texas at Austin's Electronic Music Studios from http://ems.music.utexas.edu/dwnld/mus329g.php
end
to sendSwitzerland ;;;send processed chocolate to Switzerland
ask cotedivoire 4 [ ;;;arrange processed chocolate in rows
set color 25
setxy 1 9]
ask cotedivoire 5 [
set color 25
setxy 2 9]
ask cotedivoire 6 [
set color 25
setxy 3 9]
ask cotedivoire 7 [
set color 25
setxy 0 9]
ask ghana 17 [
set color 24
setxy 0 8]
ask ghana 18 [
set color 24
setxy 1 8]
ask indonesia 21 [
set color 23
setxy 2 8]
sound:play-sound "Chewing.wav" ;;chewing sound by The University of Texas at Austin's Electronic Music Studios from http://ems.music.utexas.edu/dwnld/mus329g.php
end
to sendUSA ;;;send processed chocolate to USA
ask cotedivoire 8 [ ;;;arrange processed chocolate in rows
set color 43
setxy -10 7]
ask cotedivoire 9 [
set color 43
setxy -10 6]
ask cotedivoire 10 [
set color 43
setxy -10 9]
ask cotedivoire 11 [
set color 43
setxy -10 8]
ask cotedivoire 12 [
set color 43
setxy -11 6]
ask ghana 19 [
set color 42
setxy -11 7]
ask indonesia 22 [
set color 41
setxy -11 8]
ask indonesia 23 [
set color 41
setxy -11 9]
sound:play-sound "Chewing.wav" ;;chewing sound by The University of Texas at Austin's Electronic Music Studios from http://ems.music.utexas.edu/dwnld/mus329g.php
end
to move ;; turtle procedure
rt 1
lt 1
fd 1
end
to death ;; turtle procedure
;; when energy dips below zero, die
if energy < 0 [ die ]
end
to go
ask turtles [
if not any? turtles [ stop ]
pu
move
set energy energy - 1 ;; chocolate pieces lose energy as they move
death
]
do-plots
end
to do-plots ;; make the hunger/greed chart
set-current-plot "World of Chocolate"
set-current-plot-pen "Hunger" ;;track all turtles
plot count turtles
set-current-plot-pen "Greed" ;;track one breed. I tried tracking multiple breeds but it seems to just flatline no matter what after x ticks, so I left it with just the ghanas.
plot count ghanas
end
pink:
http://danm.ucsc.edu/~lkelley/wiki_docs/sketch_080301smooth/applet/
dizzy:
http://danm.ucsc.edu/~lkelley/wiki_docs/sketch_080229/applet/
half-baked collage:
http://danm.ucsc.edu/~lkelley/wiki_docs/sketch_080301a/applet/