this is for holding javascript data
Leon Bello edited section_Code__.tex
over 8 years ago
Commit id: 47dd1d953db94f061700c4ae186ae9f5b2292672
deletions | additions
diff --git a/section_Code__.tex b/section_Code__.tex
index 131e4a6..b7d85bb 100644
--- a/section_Code__.tex
+++ b/section_Code__.tex
...
\section{Code}
\subsection{DLA.m}
\begin{lstlisting}[language=matlab]
%% Preallocations
size = 500;
numSeeds = 1;
map = setup(size, numSeeds);
p = 0.7;
seedCounter = 0;
SC = 1;
steps = 0;
%% Simulation
r = randi(size, 1, 2); % Start a particle somewhere randomly in the lattice
while seedCounter/size^2 < p
steps = steps + 1;
randIndex = randi(2);
r(randIndex) = r(randIndex) + sign(rand() - 0.5); % randomly choose a near point to move to
if r(1) > size || r(2) > size || r(1) < 1 || r(2) < 1 % if it is outside the lattice
r = randi(size, 1, 2);
elseif isNear(r, map) == 1 && rand() < SC % if it is near a seed
map(r(1), r(2)) = 1;
r = randi(size, 1, 2);
seedCounter = seedCounter + 1;
end
if mod(steps, 10000) == 0 % Every 10000 frames
temp = map(r(1), r(2)); % keep the value of wherever the walker is
map(r(1), r(2)) = 2; % change it to 2, so we can color it different
disp(seedCounter/size^2);
disp(steps);
imagesc(map); % draw the lattice
drawnow; % forces the script to draw before the loop ends
map(r(1), r(2)) = temp; % set the map back to the previous value
end
end
\end{lstlisting}