

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

DEFINE MAXSIZE="12"
 
INT ARRAY
  angleStack(MAXSIZE)
BYTE ARRAY
  depthStack(MAXSIZE),stageStack(MAXSIZE)
BYTE stacksize=[0]
 
BYTE FUNC IsEmpty()
  IF stacksize=0 THEN RETURN (1) FI
RETURN (0)
 
BYTE FUNC IsFull()
  IF stacksize=MAXSIZE THEN RETURN (1) FI
RETURN (0)
 
PROC Push(INT angle BYTE depth,stage)
  IF IsFull() THEN Break() FI
  angleStack(stacksize)=angle
  depthStack(stacksize)=depth
  stageStack(stackSize)=stage
  stacksize==+1
RETURN
 
PROC Pop(INT POINTER angle BYTE POINTER depth,stage)
  IF IsEmpty() THEN Break() FI
  stacksize==-1
  angle^=angleStack(stacksize)
  depth^=depthStack(stacksize)
  stage^=stageStack(stacksize)
RETURN
 
INT FUNC Sin(INT a)
  WHILE a<0 DO a==+360 OD
  WHILE a>360 DO a==-360 OD
  IF a=90 THEN
    RETURN (1)
  ELSEIF a=270 THEN
    RETURN (-1)
  FI
RETURN (0)
 
INT FUNC Cos(INT a)
RETURN (Sin(a-90))
 
PROC DrawPeano(INT x BYTE y,len BYTE depth)
  BYTE stage
  INT angle=[90],a
 
  Plot(x,y)
  Push(90,depth,0)
 
  WHILE IsEmpty()=0
  DO
    Pop(@a,@depth,@stage)
    IF stage<3 THEN
      Push(a,depth,stage+1)
    FI
    IF stage=0 THEN
      angle==+a
      IF depth>1 THEN
        Push(-a,depth-1,0)
      FI
    ELSEIF stage=1 THEN
      x==+len*Cos(angle)
      y==-len*Sin(angle)
      DrawTo(x,y)
      IF depth>1 THEN
        Push(a,depth-1,0)
      FI
    ELSEIF stage=2 THEN
      x==+len*Cos(angle)
      y==-len*Sin(angle)
      DrawTo(x,y)
      IF depth>1 THEN
        Push(-a,depth-1,0)
      FI
    ELSEIF stage=3 THEN
      angle==-a
    FI
  OD
RETURN
 
PROC Main()
  BYTE CH=$02FC,COLOR1=$02C5,COLOR2=$02C6
 
  Graphics(8+16)
  Color=1
  COLOR1=$0C
  COLOR2=$02
 
  DrawPeano(69,186,7,6)
 
  DO UNTIL CH#$FF OD
  CH=$FF
RETURN