-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbrownian_motion.m
49 lines (44 loc) · 1.04 KB
/
brownian_motion.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
% Create an environment of size 100x100
size = 500;
data = 150.*ones(size,size);
% Initializing
% Max Iterations
max_iter = 10000;
% Robot Spawn position;
%x = randi(size);
%y = randi(size);
x = round(size/2);
y = round(size/2);
data(x,y) = 255; % Marking the places robot has visited with red
for k = 1:max_iter
s = 0;
while s==0
s = round(normrnd(0,1));
end
dx = 0; dy = 0;
while dx == 0 && dy == 0
dx = randi(3)-2;
dy = randi(3)-2;
end
for i = 1:abs(s)
x = max(min(x+dx,size),1);
y = max(min(y+dy,size),1);
data(x,y) = 255;
end
% Display it.
image(data);
% Initialize a color map array of 256 colors.
colorMap = turbo(256);
% Apply the colormap and show the colorbar
colormap(colorMap);
colorbar;
pause(0.001);
display(k);
end
% Display it.
image(data);
% Initialize a color map array of 256 colors.
colorMap = turbo(256);
% Apply the colormap and show the colorbar
colormap(colorMap);
colorbar;