April 30th, 2011 - (fd howFar / cosine) or walking the hypotenuse

Using COSINE function and basic trigonometry to place
turtles into a square pattern instead of a circle pattern from
a CRO 32 turtles start. Every turtle will be in a row or column of turtles. Only turtles with headig 0 or 90 or 180 or 270 get to walk the shortest distance. All others walk the hypotenuse distance of a right triangle with the adjacent leg equal to shortet distance.

TO doCircles
pd
repeat 18 [ circle wait 0.1 rt 20 ]
pu
END
TO circle
repeat 72 [ fd 0.05 rt 5 wait 0.0025 ]
END

powered by
NetLogo

view/download model file:
000create32.nlogo

## What if you create 8 turtles?

What are the EVEN and ODD?

who numbers 0, 2, 4, and 6 face headings N, E, S and W respectively.
who numbers odd turtles direction faced heading
1 NE 45
3 SE 135
5 SW 225
7 NW 315

## Heading property of a turtle - direction it is facing

The heading of a turtle is in degrees.
Turtle 0 (when you CRO 4 or CRO 8 or CRO 64 turtles) always has
heading of 0 degrees or 360 degrees and faces upward or due north.
Headings
0 degrees = North
45 degrees = NE
90 degrees = East (or right)
180 degrees = South
270 degrees = West (or left)

## COSINE is Adjacent / Hypotenuse

The turtle is walking the HYPOTENUSE distance

turtles-own [cosine walkLength]
to create32
ca
cro 32
checkerBoard
ask-concurrent turtles
[
set color black
set size 2
set pen-size 3
pd
ifelse heading <= 45 or heading >= 315
[
set cosine cos heading
]
[
ifelse heading > 45 and heading <= 135
[
set cosine cos (abs 90 - heading)
]
[
ifelse heading > 135 and heading <= 225
[
set cosine cos (abs 180 - heading)
]
[
set cosine cos (abs 270 - heading)
]
]
]
set walkLength 8 / cosine
slowWalk walkLength
cosineDance
]
end

## THINGS TO NOTICE - the output is NOT a circle

Basic Trigonometry

## two rows and two columns and cosine calculated moves to your column or your row

Nested ifelse loops are used to get the top row, the right column, the bottom row and the left column of turtles.

ifelse heading <= 45 or heading >= 315
[
set cosine cos heading
]

## With cro n the turtle 0, first EVEN turtle faces where?

heading = 0 degrees which is straight NORTH or upward on the turtle grid.

## More NetLogo procedures - needed a slowBackUp to replace bk to match slowWalk replacing fd

To doCoolPattern
set size 1
set pen-size 1
pd
repeat 36 [ slowWalk2 1.2 bk 1.2 rt 10 ]
wait 2
pu
END
TO checkerBoard
ask patches
[
ifelse remainder (pxcor + pycor) 2 = 0
[
set pcolor white
]
[
set pcolor orange
]
]
END
TO slowWalk2 [ howFar ]
repeat 10
[
fd howFar / 10 ;; Surprise output when changed divisor to 10 but left repeat at 20! Beautiful!
wait 0.01
]
END
TO slowWalk [ howFar ]
repeat 20
fd howFar / 20
wait 0.1
]
END

## PROCEDURES

to create32
ca
cro 32
ask turtles [ fd 2 pd fd 3 pu fd 2 pd fd 3 pu fd 2
]
end