clear all
close all

f =0

userInput = input('plese enter your word: ', 's')
createMovie = input('would you like to create a movie of the erosion? (y/n)', 's')
writeToGif = false
if createMovie == 'y'
    writeToGif = true
end

size(userInput,2)
N = size(userInput,2)*25;
L = max(20, size(userInput,2));
xOffset = 0;
pointInterval = L/N;
T = zeros(N+1, N+1);
x = 0:pointInterval:L;
y = 0:pointInterval:L;
if (size(userInput,2) == 1)
    N = 50
    T = zeros(51, 51);
    x = 0:pointInterval/2:L;
    y = 0:pointInterval/2:L;
end
[X,Y] = meshgrid(x,y);
k = (2.9/(1100*2750));
dt = 600;
Tmax = 100;
slope = Tmax/(N/2);



value = 100;
temp = zeros(size(userInput,2));
for (i = 1:size(userInput,2))
    if userInput(i) ~= ' '
        T = getLetter(xOffset, T, userInput(i), value);
    end
    xOffset= xOffset + 25;
end

size(x)
size(y)
size(T)
size(X)
size(Y)
surf(X,Y,T);
axis([0 L 0 L 0 Tmax]);
view(2)
if writeToGif
    saveas(gcf,['temp/',userInput,'_',sprintf('%03d',f),'.png'])
    f = f+1
end
pause(5);

numIterations = 1000
for iter = 1:numIterations
    Tnew = T;
    for i = 2:N
        for j = 2:N
            Tnew(i,j) = (((dt*k)/(pointInterval*pointInterval))*(T(i+1,j)+T(i-1,j)+T(i,j+1)+T(i,j-1)-4*T(i,j)))+T(i,j);
        end
        T=Tnew;     
    end
    surf(X,Y,T);
    axis([0 L 0 L 0 Tmax]);
    view(2)
    pause(0.01);
    if mod(iter, 100) == 0
        pause(5);
    end
    if writeToGif & mod(iter,10) == 0
        f= f+1;
        surf(X,Y,T);
        axis([0 L 0 L 0 Tmax]);
        view(2)
        saveas(gcf,['temp/',userInput,'_',sprintf('%03d',f),'.png'])
        pause(0.01);
    end
        

end

