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




order:=7;
sierpinskiArrowheadCurve(order) : turtle(_,order);
 
fcn sierpinskiArrowheadCurve(n){   // Lindenmayer system --> Data of As & Bs
   var [const] A="BF+AF+B", B="AF-BF-A";  // Production rules
   var [const] Axiom="AF";
   buf1,buf2 := Data(Void,Axiom).howza(3), Data().howza(3);  // characters
   do(n){
      buf1.pump(buf2.clear(),fcn(c){ if(c=="A") A else if(c=="B") B else c });
      t:=buf1; buf1=buf2; buf2=t;	// swap buffers
   }
   buf1		// n=7 --> 6,560 characters
}
 
fcn turtle(curve,order){	// Turtle with that can turn +-60*
   const D=10.0, a60=60;
   dir:=order.isOdd and a60 or 0;	   // start direction depends on order
   img,color := PPM(1300,1200), 0x00ff00;  // green on black
   x,y := 10, 10;
   foreach c in (curve){  // A & B are no-op during drawing
      switch(c){
	 case("F"){   // draw forward
	    a,b := D.toRectangular(dir.toFloat().toRad());
	    img.line(x,y, (x+=a.round()),(y+=b.round()), color) 
	 }
	 case("+"){ dir=(dir - a60)%360; } // turn left  60*
	 case("-"){ dir=(dir + a60)%360; } // turn right 60*
      }
   }
   img.writeJPGFile("sierpinskiArrowheadCurve.zkl.jpg");
}