Produce a graphical representation of a Sierpinski triangle of order N in any orientation.

An example of Sierpinski's triangle (order = 8) looks like this: 




use Game.SDL2;
use Game.Framework;
 
class Test {
  @framework : GameFramework;
  @colors : Color[];
  @step : Int;
 
  function : Main(args : String[]) ~ Nil {
    Test->New()->Run();
  }
 
  New() {
    @framework := GameFramework->New(GameConsts->SCREEN_WIDTH, GameConsts->SCREEN_HEIGHT, "Sierpinski Triangle");
    @framework->SetClearColor(Color->New(0,0,0));
    @colors := Color->New[1];
    @colors[0] := Color->New(178,34,34);
  }
 
  method : Run() ~ Nil {
    if(@framework->IsOk()) {
      e := @framework->GetEvent();
 
      quit := false;
      while(<>quit) {
        # process input
        while(e->Poll() <> 0) {
          if(e->GetType() = EventType->SDL_QUIT) {
            quit := true;
          };
        };
 
        @framework->FrameStart();
        @framework->Clear();
        Render(8, 20, 20, 450);
        @framework->Show();        
        @framework->FrameEnd();
      };
    }
    else {
      "--- Error Initializing Environment ---"->ErrorLine();
      return;
    };
 
    leaving {
      @framework->Quit();
    };
  }
 
  method : Render(level : Int, x : Int, y : Int, size : Int) ~ Nil {
    if(level > -1) {
      renderer := @framework->GetRenderer();
 
      renderer->LineColor(x, y, x+size, y, @colors[0]);
      renderer->LineColor(x, y, x, y+size, @colors[0]);
      renderer->LineColor(x+size, y, x, y+size, @colors[0]);
 
      Render(level-1, x, y, size/2);
      Render(level-1, x+size/2, y, size/2);
      Render(level-1, x, y+size/2, size/2);
    };
  }
}
 
consts GameConsts {
  SCREEN_WIDTH := 640,
  SCREEN_HEIGHT := 480
}
 