Code covered by the BSD License  

Highlights from
Hilbert Curve

image thumbnail
from Hilbert Curve by Federico Forte
How to draw the famous Hilbert curve, the curve that fills an area.

hilbert(n)
function [x,y] = hilbert(n)
%HILBERT Hilbert curve.
%
% [x,y]=hilbert(n) gives the vector coordinates of points
%   in n-th order Hilbert curve of area 1.
%
% Example: plot of 5-th order curve
%
% [x,y]=hilbert(5);line(x,y)
%

%   Copyright (c) by Federico Forte
%   Date: 2000/10/06 

if n<=0
  x=0;
  y=0;
else
  [xo,yo]=hilbert(n-1);
  x=.5*[-.5+yo -.5+xo .5+xo  .5-yo];
  y=.5*[-.5+xo  .5+yo .5+yo -.5-xo];
end

Contact us at files@mathworks.com