-
Notifications
You must be signed in to change notification settings - Fork 0
/
dla.m
73 lines (71 loc) · 1.87 KB
/
dla.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
%% Diffusion Limited Aggregation - KP
clear all
close all
clc
%% Initialisation
size = 101; % Size of matrix
mat = zeros(size,size); % Zeros matrix
mat(51,51) = 1; % Centre of DLA
n = 0;
%% Simulation
while(n<200) % No. of particles
theta = 2*pi*rand; % Random particle on edge of circle
x = ceil(51 + 30*cos(theta));
y = ceil(51 + 30*sin(theta));
while(1)
neig = [x-1 y+1; x y+1; x+1 y+1; x-1 y;...
x+1 y; x-1 y-1; x y-1; x+1 y-1]; % Immediate neighbours
r = randi([1,8]); % Random movement
x = neig(r,1);
y = neig(r,2);
if (x-51)^2 + (y-51)^2 > 901 % Boundary condition
break
end
% Conditions for attachment
if mat(x-1, y+1)==1
mat(x,y) = 1;
n = n+1;
break
end
if mat(x, y+1)==1
mat(x,y) = 1;
n = n+1;
break
end
if mat(x+1, y+1)==1
mat(x,y) = 1;
n = n+1;
break
end
if mat(x-1, y)==1
mat(x,y) = 1;
n = n+1;
break
end
if mat(x+1, y)==1
mat(x,y) = 1;
n = n+1;
break
end
if mat(x-1, y-1)==1
mat(x,y) = 1;
n = n+1;
break
end
if mat(x, y-1)==1
mat(x,y) = 1;
n = n+1;
break
end
if mat(x+1, y-1)==1
mat(x,y) = 1;
n = n+1;
break
end
end
% Visualising the growth
if mod(n,20)==0
a = n/20;
imwrite(not(mat), strcat('DLA_aniso', num2str(a), '.png')); % Saving image
end
end