Because of the lack of support library, this code can not be actually run!
Only for thought study.
1 voidUp ()2 {3Turtle.forward (1);4 }5 voidLeft ()6 {7Turtle.left ( -);8Turtle.forward (1);9Turtle.right ( -);Ten } One voidRight () A { -Turtle.right ( -); -Turtle.forward (1); theTurtle.left ( -); - } - voidDown () - { +Turtle.left ( the); -Turtle.forward (1); +Turtle.right ( the); A } at //let's say start with a head up - voidMoveintdirection) - { - if(direction==0) left (); - Else if(direction==1) up (); - Else if(direction==2) Right (); in ElseDown (); - } to + //A[type][step] Indicates what type of step should be used when the current state is type - inta[4][9]= the { *{0,3,0,1,2,1,0,3,0}, ${1,2,1,0,3,0,1,2,1},Panax Notoginseng{2,1,2,3,0,3,2,1,2}, -{3,0,3,2,1,2,3,0,3} the } + //B[type][step] indicates in which direction the step should go after step if the current state is type A //0 left, 1 up, 2 right, 3 down the intb[4][8]= + { -{1,1,2,3,3,2,1,1}, ${3,3,2,1,1,2,3,3}, ${3,3,0,1,1,0,3,3}, -{1,1,0,3,3,0,1,1} - } the - voidDrawintTypeintLevel//type:0 Lower left, 1 upper left, 2 right, 3 lower right, level represents the number of iterationsWuyi { the if(!level)return; -Draw (a[type][0]); Wu for(intI=1;i<9; i++) - { AboutMove (b[type][i-1]); $ Draw (A[type][i]); - } -}
When you call Draw (0,n), the above code can theoretically draw the N-order Hilbert curve.
C + + analog turtle to draw Hilbert curve