%% Script to define how the Tiger got its stripes
% You have two chemicals which are distributed nonuniformly through
% the skin of the animal. They react with each other, and they each diffuse from areas with high
% concentrations to areas with low concentrations.
%
% It turns out that fiddling the reaction rates
% and the diffusion rates can yield all sorts of different patterns which look very similar to
% patterns you see in nature.
% An explanation of how this model describes the reaction of chemicals A
% and B can be found at http://www.karlsims.com/rd.html, by Karl Sims
%
% Code adapted for Octave by Michael Ralph.
%% Variables to manipulate
% Reaction rates - how molecules are made and destroyed
f=.055; % feed rate
k=.062; % kill rate
% Diffusion rates - how molecules move
da = 1;
db = .5;
% Model visualization - higher values = higher speed, jumpier animation
speed = 1000 % how many frames to skip between image plots
%% Function of the model
% Size of grid
width = 128;
% 5,000 simulation seconds with 4 steps per simulated second
dt = .25;
stop = 5000;
R = speed
%% Establish initial conditions
t = 0;
% Initialize A to one
A = ones(width);
% Initialize B to zero which a clump of ones
B = zeros(width);
B(51:60 ,51:70) = 1;
B(61:80 ,71:80) = 1;
nframes = 1;
% Add a scaled-color image
hi = imagesc(B);
%hi.CDataMapping = 'scaled';
while (t < stop)
anew = A + (da*(-A + .20*(circshift(A,[ 1, 0]) + circshift(A,[-1, 0]) + circshift(A,[ 0, 1]) + circshift(A,[ 0,-1])) + .05*(circshift(A,[ 1, 1]) + circshift(A,[-1, 1]) + circshift(A,[-1,-1]) + circshift(A,[ 1,-1]))) - A.*B.^2 + f*(1-A))*dt;
bnew = B + (db*(-B + .20*(circshift(B,[ 1, 0]) + circshift(B,[-1, 0]) + circshift(B,[ 0, 1]) + circshift(B,[ 0,-1])) + .05*(circshift(B,[ 1, 1]) + circshift(B,[-1, 1]) + circshift(B,[-1,-1]) + circshift(B,[ 1,-1]))) + A.*B.^2 - (k+f)*B)*dt;
A = anew;
B = bnew;
t = t+dt;
if (R < 2)
hi = imagesc(B)
R = speed
else
Rnew = (R - 1)
R = Rnew
endif
ht.String = ['Time = ' num2str(t)];
drawnow('expose');
nframes = nframes+1;
end