-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviewmap.m
More file actions
executable file
·75 lines (59 loc) · 1.47 KB
/
viewmap.m
File metadata and controls
executable file
·75 lines (59 loc) · 1.47 KB
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
74
function viewmap(mapfile, mode)
%Plots the map. See map_convert
% if mode == 0 show walls
% if mode ~= 0 show track
if nargin == 1,
mode = 0;
end
map=map_convert(mapfile);
[maprows,mapcols]=size(map);
[X,Y]=meshgrid(1:20,1:20);
plot(X,Y,'k'); hold on
plot(Y,X,'k');
axis([0, mapcols+1, 0, maprows+1]);
axis off
for i=1:maprows,
for j=1:mapcols,
if mode == 0,
if (map(i,j) == 1)
placeblock([16-i,j]);
end;
else
if (map(i,j) == 0)
placetrack([16-i,j]);
end
end
end
end
%plot row indices
for i = 1:maprows,
c=sprintf('%d',i);
text(0.5,maprows-i+1+0.5,c,'FontSize',8);
text(mapcols+1+0.5,maprows-i+1+0.5,c,'FontSize',8);
end
%plot col indices
for i = 1:mapcols,
c=sprintf('%d',i);
text(0.5+i,maprows+1+0.5,c,'FontSize',8);
text(0.5+i,0.5,c,'FontSize',8);
end
hold off
end
function placeblock(position)
position=[position(2) position(1)];
rectangle('Position',[position,1,1],'FaceColor','r');
end
function placetrack(position)
position=[position(2) position(1)];
rectangle('Position',[position,1,1],'FaceColor','y');
end
function eraseblock(position)
position=[position(2) position(1)];
rectangle('Position',[position,1,1],'FaceColor','w');
end
function placestep(position,i)
position=[position(2)+0.1 position(1)+0.1];
rectangle('Position',[position,0.8,0.8],'FaceColor','y');
c=sprintf('%d',i);
text(position(1)+0.2,position(2)+0.2,c,'FontSize',10);
end