clear
clf

%initial conditions
a=100;
b=100;
xorig=50; %x point
yorig=50; %y point
m=zeros(a,b); %mag matrix 
m(xorig,yorig)=100; %magnitude at source start 
it=1000; %iterations
mNew = zeros(a,b);
e=100;
k=100;

%Island Data
Z=zeros(e,k);
Z(65:80,1:3)=1;
Z(66:79,3:5)=1;
Z(67:78,5:7)=1;
Z(69:78,7:8)=1;
Z(76:78,8:10)=1;
Z(77:79,10:12)=1;
Z(78:80,12:13)=1;
Z(79:80,13:15)=1;
Z(80:81,15:16)=1;
Z(81:81,16:17)=1;

Z(69:75,9:10)=1;
Z(69:76,11:12)=1;
Z(72:74,13:14)=1;
Z(74:75,13)=1;
Z(71:72,13)=1;
Z(68,18:22)=1;
Z(67,20:24)=1;
Z(66,22:24)=1;
Z(65,23:25)=1;
Z(64,25:26)=1;
%Solomon Islands
Z(63,26)=1;
Z(62,25)=1;
Z(62,24)=1;
Z(61,23)=1;
Z(70,33:34)=1;
Z(71,34:35)=1;
Z(72,35:36)=1;
Z(73,36:37)=1;
Z(77,37)=1;
Z(78,38)=1;
Z(79,39)=1;
Z(80,40)=1;
Z(75,40)=1;
Z(76,41)=1;
Z(78,43)=1;
Z(79,43)=1;
Z(82,43)=1;
Z(83,44)=1;

%Tip of Australia
Z(100,1:7)=1;
Z(99,1:6)=1;
Z(98,1:5)=1;
Z(95:97,1:4)=1;
Z(92:95,1:3)=1;
Z(87:92,1:2)=1;
Z(85:87,2)=1;

%Marshall Islands
Z(56,54)=1;
Z(59,56)=1;
Z(60,58)=1;
Z(62,59)=1;
Z(64,60)=1;
Z(66,62)=1;

%Vanuatu Islands
Z(97,55:57)=1;
Z(98,56)=1;
Z(96,56)=1;
Z(98,59)=1;
Z(95,59)=1;

f=1;


for t=1:it
    for i=2:a-1
        for j=2:b-1
            mNew(i+1,j) = mNew(i+1,j)+0.7*m(i,j);
            mNew(i,j+1)= mNew(i,j+1)+0.7*m(i,j);
            mNew(i-1,j) = mNew(i-1,j)+0.7*m(i,j);
            mNew(i,j-1) = mNew(i,j-1)+0.7*m(i,j);
        end
    end
    m=mNew;
    imagesc(m)
     if mod(t+19,10)== 0
         f=f+1
        saveas(gcf, ['final_project_', sprintf('%03d',f),'.png'])
        pause(.001)
    end
%     hold on
%     imagesc(Z) %couldn't get them to plot at the same time
end








