C + + analog turtle to draw Hilbert curve

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.