function [x,y] = hcurve(level)

% [X,Y] = HCURVE(N) calculates and returns the co-ordinates of
% the nodes of the n-th iteration of Hilbert's space-filling curve
% using recursion.
% It also draws the curve at the n-th iteration.

% end of recursion
if level == 0
  x0 = 0;
  y0 = 0;
  
  %calculate new co-ordinates
  x = .5*[-.5+y0 -.5+x0 .5+x0 .5-y0];
  y = .5*[-.5+x0 .5+y0 .5+y0 -.5-x0];
  
%recursive matryoshka call
else
  [x0,y0] = hcurve(level-1);
  
  %calculate new co-ordinates

%missing lines here

end

plot(x,y);
