

Task
Produce a graphical or ASCII-art representation of a Peano curve of at least order 3.

 
Module Peano_curve {
Cls 1, 0
Const Center=2
Report Center, "Peano curve"
let factor=.9, k=3, wi=k^4
let wi2=min.data(scale.x*factor, scale.y*factor), n=wi2/wi
let (dx, dy)=((scale.x-wi2)/2, (scale.y-wi2)/2)
dx+=k*1.2*twipsX
dy+=k*1.2*twipsY
move dx, dy
pen 11 {
      Peano(0,0,wi,0, 0)
}
 
sub Peano(x, y, lg, i1, i2)
      if lg ==1  then 
            draw to  x*n+dx , y*n+dy
            return
      end if
      lg/=k
      Peano(x+2*i1*lg, y+2*i1*lg, lg, i1, i2)
      Peano(x+(i1-i2+1)*lg, y+(i1+i2)*lg, lg, i1, 1-i2)
      Peano(x+lg, y+lg, lg, i1, 1-i2)
      Peano(x+(i1+i2)*lg, y+(i1-i2+1)*lg, lg, 1-i1, 1-i2)
      Peano(x+2*i2*lg, y+2*(1-i2)*lg, lg, i1, i2)
      Peano(x+(1+i2-i1)*lg, y+(2-i1-i2)*lg, lg, i1, i2)
      Peano(x+2*(1-i1)*lg, y+2*(1-i1)*lg, lg, i1, i2)
      Peano(x+(2-i1-i2)*lg, y+(1+i2-i1)*lg, lg, 1-i1, i2)
      Peano(x+2*(1-i2)*lg, y+2*i2*lg, lg, 1-i1, i2)      
end sub
}
Peano_curve
 