%% Matlab freedom
nPoints = 25;
L = 40*membrane(1,nPoints);
gridSide = linspace(0,51,2*nPoints+1);
[X,Y] = meshgrid(gridSide, gridSide);
Ldot = 0;
%L = kernelConvolution(L,3);
for i = 1:1000
% See the membrane as a net of balls attached by springs. The ball
% moves by newtonial mechanics, and the force on it is proportional to
% the distance between the ball and its 4-connected neighbors. Each
% ball is thought to slide along e vertical bar, so it cannot move
% sideways.
verticalDistanceLeftRight = diff(L,1,2);
forceLeftRight = sqrt(1+verticalDistanceLeftRight.^2).*sign(verticalDistanceLeftRight);
verticalDistanceUpDown = diff(L,1,1);
forceUpDown = sqrt(1+verticalDistanceUpDown.^2).*sign(verticalDistanceUpDown);
forceTotal = [forceLeftRight zeros(size(forceLeftRight,1),1)] - ...
[zeros(size(forceLeftRight,1),1) forceLeftRight] + ...
[forceUpDown; zeros(1,size(forceUpDown,2))] - ...
[zeros(1,size(forceUpDown,2)); forceUpDown];
forceTotal(1:end,[1 end]) = 0;
forceTotal([1 end],1:end) = 0;
Ldot = Ldot + 0.01*(forceTotal - Ldot);
L = L + Ldot;
logoFig = figure('Color',[0 0 0]);
logoax = axes('CameraPosition', [-193.4013 -265.1546 220.4819],...
'CameraTarget',[26 26 10], ...
'CameraUpVector',[0 0 1], ...
'CameraViewAngle',9.5, ...
'DataAspectRatio', [1 1 .9],...
'Position',[0 0 1 1], ...
'Visible','off', ...
'XLim',[1 51], ...
'YLim',[1 51], ...
'ZLim',[-13 40], ...
'parent',logoFig);
s = surface(X,Y,L, ...
'EdgeColor','none', ...
'FaceColor',[0.9 0.2 0.2], ...
'FaceLighting','phong', ...
'AmbientStrength',0.3, ...
'DiffuseStrength',0.6, ...
'Clipping','off',...
'BackFaceLighting','lit', ...
'SpecularStrength',1.1, ...
'SpecularColorReflectance',1, ...
'SpecularExponent',7, ...
'Tag','TheMathWorksLogo', ...
'parent',logoax);
l1 = light('Position',[40 100 20], ...
'Style','local', ...
'Color',[0 0.8 0.8], ...
'parent',logoax);
l2 = light('Position',[.5 -1 .4], ...
'Color',[0.8 0.8 0], ...
'parent',logoax);
F = getframe(logoax);
save ( sprintf ( 'Image%0.3d.mat', i ), 'F' );
close(logoFig);
end