This repository has been archived by the owner on Apr 6, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
map.m
44 lines (37 loc) · 1.19 KB
/
map.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
function [ax, x, y] = map(fh, MapSize, N)
% Creates a square map of side length 2 x MapSize
% arguments
% fh [figure obj] figure container
% MapSize [int] size for map
% N [int] amount of cities to populate map with
% returns
% ax [axes obj] axes used for map
% x, y [N size array float] arrays of city coordiantes
if nargin < 2
N = 5;
end
if nargin < 1
fh = figure();
end
% Create axis used for map
ax = axes(fh, 'NextPlot','add');
axis(ax, MapSize * [-1 1 -1 1]);
set(ax, 'Color', '#96C3CE');
set(ax, 'DataAspectRatio', [1 1 1]);
% Select city points
x = 2 * MapSize * rand(1,N) - MapSize;
y = 2 * MapSize * rand(1,N) - MapSize;
% Populate with islands (must be done loopwise,
% as a new island should be created for each set of coordinates
for i = 1:N
island(ax, x(i), y(i), 'c');
end
% Plot cities and set to square resolution
plot(x, y, '^', 'MarkerSize', 5,'MarkerFaceColor', [0 0 0]);
% Populate cities with names
text( ...
x + 20, y, city(N), ...
'HorizontalAlignment', 'left', ...
'BackgroundColor', 'w' ...
);
end