#Set model parameters

#square neighborhood radius
R = 3
#number of states / colors
K = 8
#excitation threshhold
T = 6

#initial conditions on 300x300 lattice
initial = random_state_v2((300,300), K, 2.0/9)

#initialize CA object with chosen parameters and initial condition
spirals = greenberg_hastings(initial, R, K, T)
#evolve the CA for 300 time steps
spirals.evolve(300)

"""
Explanation: Example code for using Greenberg-Hastings CA module
See documenation in Greenberg_Hastings.py for details on the Greenberg-Hastings model. 
Classic spiral wave behavior
End of explanation
"""


spacetime_animation(spirals.get_spacetime(), colors = plt.cm.rainbow)

"""
Explanation: Animate the spacetime field produced by the above code
End of explanation
"""


#Set model parameters

#square neighborhood radius
R = 3
#number of states / colors
K = 8
#excitation threshhold
T = 6

#initial conditions on 300x300 lattice
initial = random_state_v2((300,300), K, 2.0/9)

#initialize CA object with chosen parameters and initial condition
spirals = greenberg_hastings(initial, R, K, T)
#evolve the CA for 300 time steps
spirals.animate(time = 300)

"""
Explanation: You can also animate on the fly using the .animate() method. We run the same code again, but use .animate(duration = 300) instead of .evolve(300). Both methods produce a 300x300x300 spacetime field that can be visualized with spacetime_animation.
End of explanation
"""


spacetime_animation(spirals.get_spacetime(), colors = plt.cm.rainbow)

"""
Explanation: Again we can still use spacetime_animation, this time if we want to watch that specific evolution again. Since the .animate() method animates on the fly, it is typically slower.
End of explanation
"""


R = 1
K = 4
T = 2
initial = random_state_v1((250, 250), 0.2)
example1 = greenberg_hastings(initial, R, K, T)

example1.evolve(300)

spacetime_animation(example1.get_spacetime(), colors = plt.cm.rainbow)

"""
Explanation: Some phenomonolgy: exploring parameter space and adding stochastic driving
Some fun travelling particles and collisions
End of explanation
"""


R = 1
K = 10
T = 2
initial = random_state_v1((200, 200), 0.5)
example2 = greenberg_hastings(initial, R, K, T)

example2.drive(200, 0.02)

spacetime_animation(example2.get_spacetime(), colors = plt.cm.rainbow)

"""
Explanation: Global oscillations induced by stochastic driving
Start with very low driving, just see random sprinkling of excitations, no oscillations 
Driving strength: 0.02
End of explanation
"""


R = 1
K = 10
T = 2
initial = random_state_v1((200, 200), 0.5)
example3 = greenberg_hastings(initial, R, K, T)

example3.drive(200, 0.1)

spacetime_animation(example3.get_spacetime(), colors = plt.cm.rainbow, interval = 5)

"""
Explanation: Keep same model parameters and initial conditions, now just bump up the driving rate and see global oscillations
Driving strength: 0.1
End of explanation
"""


R = 1
K = 10
T = 2
initial = random_state_v1((200, 200), 0.5)
example4 = greenberg_hastings(initial, R, K, T)

example4.drive(300, 0.5)

spacetime_animation(example4.get_spacetime(), colors = plt.cm.rainbow, interval = 5)

"""
Explanation: Increase driving further, collective oscillations become more pronounced
Driving strength: 0.5
End of explanation
"""


