Task

Draw a Cantor set.



See details at this Wikipedia webpage:   Cantor set

class CantorSet {
  WIDTH : static : Int;
  HEIGHT : static : Int;
  lines : static : Char[,];
 
  function : Init() ~ Nil {
    WIDTH := 81;
    HEIGHT := 5;
    lines := Char->New[HEIGHT, WIDTH];
 
    each(i : HEIGHT) {
      each(j : WIDTH) {
        lines[i,j] := '*';
      };
    };
  }
 
  function : Cantor(start : Int, len : Int, index : Int) ~ Nil {
    seg : Int := len / 3;
 
    if(seg = 0) {
      return;
    };
 
    for(i := index; i < HEIGHT; i += 1;) {
      for(j := start + seg; j < start + seg * 2; j += 1;) {
        lines[i,j] := ' ';
      };
    };
 
    Cantor(start, seg, index + 1);
    Cantor(start + seg * 2, seg, index + 1);
  }
 
  function : Main(args : String[]) ~ Nil {
    Init();
 
    Cantor(0, WIDTH, 1);
    each(i : HEIGHT) {
      each(j : WIDTH) {
        lines[i,j]->Print();
      };
      ""->PrintLine();
    };
  }
}