-
Notifications
You must be signed in to change notification settings - Fork 2
/
snake_read.m
35 lines (32 loc) · 1.04 KB
/
snake_read.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
function [xs, ys] = snake_read()
%SNAKE_READ Read snake control points
% [XS, YS] = SNAKE_READ(IMAGE) displays the image in a new figure, then
% records the position of each click of button 1 of the mouse in the
% figure, and stops after recording the position of one click of another
% button. The snake is drawn as it goes along. XS is a column vector of
% x-coordinates and YS a column vector of y-coordinates.
%
% See also SNAKE_DEMO
hold on; % and keep it there while we plot
xs = [];
ys = []; % initialisations
xold = 0;
yold = 0;
but = 1;
i = 0;
while i < 4 % while button 1 being pressed
[xi, yi, but] = ginput(1); % get a point
xs = [xs; xi]; % append its coords to vector
ys = [ys; yi];
if xold;
plot([xold xi], [yold yi], 'go-'); % draw as we go
else
plot(xi, yi, 'go'); % first point on its own
end;
xold = xi;
yold = yi;
i = i + 1;
end;
plot([xi xs(1)], [yi ys(1)], 'g-'); % join first to last points
hold off;
end