Pattern Generator
WHAT IS IT?
This project lets the user explore making patterns using turtles.
HOW TO USE IT
The buttons next to the Graphics Canvas are divided into four different categories. The first category is Basic Commands. The buttons and sliders in this category perform simple StarLogo commands. The second category is Setup Patterns. The buttons and sliders in this category arrange the turtles in more complex configurations. The third category is Action.
The five buttons in this category move the turtles according to collections of simple commands called procedures. You can experiment with these buttons to learn more about what they do.
For example, you can try the following exploration: -Press the "clear all" button to begin. -Create 20 turtles by setting the "number" slider to 20 and then pressing the "create number" button. -Put the turtles' pens down using the "pen down" button. -Press the "pattern-1" button.
EXPLORATIONS
Try combining the patterns from the Action category with some of the buttons in the Basic Commands category. You can also create your own buttons under the Custom Buttons category.
Turtle procedures
;; go1 procedure
;; called by the pattern-1 button
;; The first 10 turtles turn 1 degree to the right, hatch new turtles
;; set their color and turn in a crude circle then die.
;;
to go1
if who < 10 [
rt 1
hatch [
setc who / 30
repeat 36
[fd 4 rt 10]
die
]
]
end
;; go2 procedure
;; called by the pattern-2 button
;; With the first 20 turtles, if the who number is even, turn 1 degree
;; to the right, hatch a new turtle, set its color and turn in a crude
;; circle then die. If the who number is odd, do the same turning left
;; instead of right.
;;
to go2
if who < 20 [
ifelse (who mod 2) = 0
[ rt 1
hatch [
setc who / 20
repeat 36 [fd 4 rt 10]
die
]
]
[ lt 1
hatch [
setc who / 20
repeat 36 [fd 4 lt 10]
die
]
]
]
end
;; go3 procedure
;; called by the pattern-3 button
;; With the first 40 turtles, if the who number is even, turn 2 degrees
;; to the right, go forward 1 step, hatch a new turtle, set its color and turn in a crude
;; in an arc then die. If the who number is odd, do the same turning left
;; instead of right.
;;
to go3
if who < 40 [
ifelse (who mod 2) = 0
[ rt 2
fd 1
hatch [
setc 100 + (who / 50)
repeat 20 [fd 1 rt 10]
die
]
]
[ lt 2
fd 1
hatch [
setc 100 + (who / 50)
repeat 20 [fd 1 lt 10]
die
]
]
]
end
;; go4 procedure
;; called by the pattern-4 button
;; Go forward 4 steps and turn 10 degrees to the right
;;
to go4
fd 4
rt 10
end
;; go4 procedure
;; called by the pattern-5 button
;; If the who number is even, go forward 4 steps and turn 10 degrees
;; to the right, else go forward 4 steps and turn 10 degrees to the left.
;;
to go5
ifelse (who mod 2) = 0
[fd 4 rt 10]
[fd 4 lt 10]
end
;; turtle-setup1 procedure
;; called by the setup1 observer button
;; Turn 15 degrees to the right, and then create a ring "petals" times where
;; the number of petals is set by the user with the petals slider
;;
to turtle-setup1 ;part of the code for the create-flower button
rt 15
repeat petals [
repeat 36 [
repeat 3 [
hatch [
setc who
seth ycor * 3
]
fd 1
]
rt 10
]
rt (360 / petals)
]
end
;; turtle-setup3 procedure
;; called by the setup3 observer button
;;
;;
to turtle-setup3 ;part of the code for the create-clover button
fd 20
repeat who [
fd 1
rt 5
]
setc who
end
to none ;a dummy procedure to put in the buttons which act as text
end
Observer procedures
;; setup1 procedure
;; called by the create-flower button
;; Clears all and create a single turtle that executes the turtle procedure
;; turtle-setup1
;;
to setup1
ca
crt 1
ask-turtles [turtle-setup1]
end
;; setup2 procedure
;; called by the create-2-rings button
;; Clears all and creates 20 turtles that go forward 30 and turn around.
;; Then creates another 20 turtles who go forward 10.
;;
to setup2
ca
crt 20 ask-turtles [fd 30 rt 180]
crt 20 ask-turtles [fd 10]
end
;; setup3 procedure
;; called by the create-clover button
;; Clears all and creates 360 turtles that execute the turtle procedure
;; turtle-setup3
;;
to setup3 ;the setup procedure for the create-clover button
ca
crt 360
ask-turtles [turtle-setup3]
end
