Gaussian Distribution
WHAT IS IT?
This project explores gaussian distribution. In this model, agents represent the balls that are dropped into the arrangements of red pins from directly above the apex. Another hidden turtle acts as the ball creator. The red pins and the orange walls are patches. Agents move as follows: If the current ball above a red pin, go right or left one step (chosen randomly.) If the current ball is directly above another yellow ball, stop. If the current ball is directly above the green bar, stop. Then current ball goes forward 1 step. The speed of fall is changed using the speed slider. The left-right bias (direction ball will move when a peg is encountered) is changed using the left-right slider.
HOW TO USE IT
Set the speed of fall using the speed slider. Set the left-right bias (direction ball will move when a peg is encountered) using the left-right slider. Click the setup button to clear balls from the previous run, redraw the green bar and instantiate the ball creator. Click the start button to start the simulation. The remove-bar button removes the green bar so all the balls will fall through. The add-bar will redraw the green bar so the balls will collect in bars.
THINGS TO NOTICE
Watch what happens when the left-right bias is changed. Add the green bar and watch the shape of the bars as the balls are collected in columns.
EXPLORATIONS
What would happen with a different arrangement of red pins?
STARLOGO FEATURES
The statement "ifelse left-right > random 100" is used to determine which way a ball should move when a red pin is encountered. This works because random 100 returns a value between 0 - 99 with equal probability AND left-right percent of the time the number chosen at random will be less that the left-right value. You can think of it as tossing a 100-sided die, if the die is less than the left-right value, the ball goes right, otherwise the ball goes left on step.
Turtle procedures
breeds [
ball ; the balls
ball-creator ; the ball creator
]
turtles-own [
currentdepth ;
hatchtwo
]
;; ball-setup procedure
;; called by the setup procedure
;; Position the ball-creator and set its heading and color.
;;
to ball-setup
setxy 0 screen-half-height
seth 180
setc black
end
;; fall procedure
;; called by the start procedure and the fall button
;; Ball behavior is specified in this procedure.
;; If current ball is above another yellow ball or the green bar, then stop.
;; If current ball is above a red peg, move randomly right or left.
;; Wait a bit then move current ball forward 1.
;;
to fall
if breed = ball
[
if ((color-at 0 -1) = yellow) or ((pc-at 0 -1) = green)
[stop]
if (pc-at 0 -1) = red [ ;turn at red squares
ifelse left-right > random 100
[setx xcor + 1]
[setx xcor - 1]
]
wait (10 - speed) / 500
fd 1
]
end
;; drop-ball procedure
;; called by the start procedure and the drop-ball button
;; The ball-creator hatches new balls and sets them in motion.
;;
to drop-ball
if breed = ball-creator [
hatch [
sety screen-half-height
setbreed ball
setc yellow
seth 180
fd 1
]
]
end
Observer procedures
;; setup procedure
;; called by the setup button
;; Clears up any leftover turtles then cleans up the yellow patches
;; Creates the ball creator and asks it to setup the balls. and the bar is added
;; at the bottom
;;
to setup
ask-turtles [die]
ask-patches [
if pc = yellow [setpc black]
]
create-ball-creator 1
ask-ball-creator [ball-setup]
add-bar
end
;; add-bar procedure
;; called by the setup procedure and by clicking the add-bar button
;; Redraw the green bar at the bottom of the screen.
;; (This is done so the balls do not fall through.)
;;
to add-bar
ask-patches [
if ycor = (0 - screen-half-height)
[setpc green]
]
end
;; remove-bar procedure
;; called by the remove-bar button
;; Remove the green bar at the bottom of the screen.
;; (This is done so the balls fall through rather than collecting.)
;;
to remove-bar
ask-patches [
if ycor = (0 - screen-half-height)
[setpc black]
]
end
;; start procedure
;; called by the start procedure
;; Start two buttons running: the "fall" button and the "drop-ball" button.
;;
to start
startfallbutton
startdrop-ballbutton
end
;; stopit procedure
;; called by the stopit button
;; Stops two buttons: the "fall" button and the "drop-ball" button.
;;
to stopit
stopfallbutton
stopdrop-ballbutton
end
