ASCII art H trees












9












$begingroup$


An H tree is a fractal tree structure that starts with a line. In each iteration, T branches are added to all endpoints. In this challenge, you have to create an ASCII representation of every second H tree level.



The first level simply contains three hyphen-minus characters:



---


The next levels are constructed recursively:




  • Create a 2x2 matrix of copies from the previous level, separated by three spaces or lines.

  • Connect the centers of the copies with ASCII art lines in the form of an H. Use - for horizontal lines, | for vertical lines, and + whenever lines meet each other.


Second level



-+-   -+-
| |
+-----+
| |
-+- -+-


Third level



-+-   -+-   -+-   -+-
| | | |
+--+--+ +--+--+
| | | | | |
-+- | -+- -+- | -+-
| |
+-----------+
| |
-+- | -+- -+- | -+-
| | | | | |
+--+--+ +--+--+
| | | |
-+- -+- -+- -+-


Rules




  • Input is an integer representing the level of the ASCII art H tree as described above (not the actual H tree level), either zero- or one-indexed.

  • Output is flexible. For example, you can print the result or return a newline-separated string, a list of strings for each line, or a 2D array of characters.

  • You must use -, |, + and space characters.

  • Trailing space and up to three trailing white-space lines are allowed.


This is code golf. The shortest answer in bytes wins.










share|improve this question









$endgroup$








  • 2




    $begingroup$
    Related: Create an “H” from smaller “H”s
    $endgroup$
    – nwellnhof
    Nov 25 '18 at 11:45
















9












$begingroup$


An H tree is a fractal tree structure that starts with a line. In each iteration, T branches are added to all endpoints. In this challenge, you have to create an ASCII representation of every second H tree level.



The first level simply contains three hyphen-minus characters:



---


The next levels are constructed recursively:




  • Create a 2x2 matrix of copies from the previous level, separated by three spaces or lines.

  • Connect the centers of the copies with ASCII art lines in the form of an H. Use - for horizontal lines, | for vertical lines, and + whenever lines meet each other.


Second level



-+-   -+-
| |
+-----+
| |
-+- -+-


Third level



-+-   -+-   -+-   -+-
| | | |
+--+--+ +--+--+
| | | | | |
-+- | -+- -+- | -+-
| |
+-----------+
| |
-+- | -+- -+- | -+-
| | | | | |
+--+--+ +--+--+
| | | |
-+- -+- -+- -+-


Rules




  • Input is an integer representing the level of the ASCII art H tree as described above (not the actual H tree level), either zero- or one-indexed.

  • Output is flexible. For example, you can print the result or return a newline-separated string, a list of strings for each line, or a 2D array of characters.

  • You must use -, |, + and space characters.

  • Trailing space and up to three trailing white-space lines are allowed.


This is code golf. The shortest answer in bytes wins.










share|improve this question









$endgroup$








  • 2




    $begingroup$
    Related: Create an “H” from smaller “H”s
    $endgroup$
    – nwellnhof
    Nov 25 '18 at 11:45














9












9








9


2



$begingroup$


An H tree is a fractal tree structure that starts with a line. In each iteration, T branches are added to all endpoints. In this challenge, you have to create an ASCII representation of every second H tree level.



The first level simply contains three hyphen-minus characters:



---


The next levels are constructed recursively:




  • Create a 2x2 matrix of copies from the previous level, separated by three spaces or lines.

  • Connect the centers of the copies with ASCII art lines in the form of an H. Use - for horizontal lines, | for vertical lines, and + whenever lines meet each other.


Second level



-+-   -+-
| |
+-----+
| |
-+- -+-


Third level



-+-   -+-   -+-   -+-
| | | |
+--+--+ +--+--+
| | | | | |
-+- | -+- -+- | -+-
| |
+-----------+
| |
-+- | -+- -+- | -+-
| | | | | |
+--+--+ +--+--+
| | | |
-+- -+- -+- -+-


Rules




  • Input is an integer representing the level of the ASCII art H tree as described above (not the actual H tree level), either zero- or one-indexed.

  • Output is flexible. For example, you can print the result or return a newline-separated string, a list of strings for each line, or a 2D array of characters.

  • You must use -, |, + and space characters.

  • Trailing space and up to three trailing white-space lines are allowed.


This is code golf. The shortest answer in bytes wins.










share|improve this question









$endgroup$




An H tree is a fractal tree structure that starts with a line. In each iteration, T branches are added to all endpoints. In this challenge, you have to create an ASCII representation of every second H tree level.



The first level simply contains three hyphen-minus characters:



---


The next levels are constructed recursively:




  • Create a 2x2 matrix of copies from the previous level, separated by three spaces or lines.

  • Connect the centers of the copies with ASCII art lines in the form of an H. Use - for horizontal lines, | for vertical lines, and + whenever lines meet each other.


Second level



-+-   -+-
| |
+-----+
| |
-+- -+-


Third level



-+-   -+-   -+-   -+-
| | | |
+--+--+ +--+--+
| | | | | |
-+- | -+- -+- | -+-
| |
+-----------+
| |
-+- | -+- -+- | -+-
| | | | | |
+--+--+ +--+--+
| | | |
-+- -+- -+- -+-


Rules




  • Input is an integer representing the level of the ASCII art H tree as described above (not the actual H tree level), either zero- or one-indexed.

  • Output is flexible. For example, you can print the result or return a newline-separated string, a list of strings for each line, or a 2D array of characters.

  • You must use -, |, + and space characters.

  • Trailing space and up to three trailing white-space lines are allowed.


This is code golf. The shortest answer in bytes wins.







code-golf ascii-art fractal






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 25 '18 at 11:29









nwellnhofnwellnhof

6,53511125




6,53511125








  • 2




    $begingroup$
    Related: Create an “H” from smaller “H”s
    $endgroup$
    – nwellnhof
    Nov 25 '18 at 11:45














  • 2




    $begingroup$
    Related: Create an “H” from smaller “H”s
    $endgroup$
    – nwellnhof
    Nov 25 '18 at 11:45








2




2




$begingroup$
Related: Create an “H” from smaller “H”s
$endgroup$
– nwellnhof
Nov 25 '18 at 11:45




$begingroup$
Related: Create an “H” from smaller “H”s
$endgroup$
– nwellnhof
Nov 25 '18 at 11:45










4 Answers
4






active

oldest

votes


















7












$begingroup$


Canvas, 20 19 bytes



ø⁸«╵[↷L⇵;l⇵└┌├-×╋‼│


Try it here!



Explanation:



ø                    push an empty canvas
⁸«╵[ repeat input*2 + 1 times
↷ rotate clockwise
L⇵ ceil(width/2)
;l⇵ ceil(height/2); leaves stack as [ ⌈½w⌉, canvas, ⌈½h⌉ ]
└┌ reorder stack to [ canvas, ⌈½w⌉, ⌈½h⌉, ⌈½w⌉ ]
├ add 2 to the top ⌈w÷2⌉
-× "-" * (2 + ⌈w÷2⌉)
╋ in the canvas, at (⌈w÷2⌉; ⌈h÷2⌉) insert the dashes
‼ normalize the canvas (the 0th iteration inserts at (0; 0) breaking things)
│ and palindromize horizontally





share|improve this answer











$endgroup$





















    7












    $begingroup$


    Charcoal, 22 bytes



    P-²FNF²«⟲T²+×⁺²κX²ι←‖O


    Try it online! Link is to verbose version of code. 0-indexed. Explanation:



    P-²


    Print the initial three -s, leaving the cursor in the middle.



    FN


    Repeat for the number of times given.



    F²«


    Repeat twice for each H. Each loop creates a slightly bigger H from the previous loop, but we only want alternate Hs.



    ⟲T²


    Rotate the figure.



    +×⁺²κX²ι←


    Draw half of the next line.



    ‖O


    Reflect to complete the step.



    The result at each iteration is as follows:



    ---

    | |
    +---+
    | |

    -+- -+-
    | |
    +-----+
    | |
    -+- -+-

    | | | |
    +-+-+ +-+-+
    | | | | | |
    | |
    +-------+
    | |
    | | | | | |
    +-+-+ +-+-+
    | | | |

    -+- -+- -+- -+-
    | | | |
    +--+--+ +--+--+
    | | | | | |
    -+- | -+- -+- | -+-
    | |
    +-----------+
    | |
    -+- | -+- -+- | -+-
    | | | | | |
    +--+--+ +--+--+
    | | | |
    -+- -+- -+- -+-





    share|improve this answer









    $endgroup$













    • $begingroup$
      If you wonder how a 5-th level H looks like, a quick zoomed-out glance: i.imgur.com/EGapcrS.png
      $endgroup$
      – Paul
      Nov 25 '18 at 17:59



















    1












    $begingroup$


    Python 2, 227 bytes





    L=len
    def f(n):
    if n==1:return[['-']*3]
    m=[l+[' ']*3+l for l in f(n-1)];w=L(m[0]);y=L(m)/2;x=w/4-1;m=map(list,m+[' '*w,' '*x+'-'*(w-x-x)+' '*x,' '*w]+m)
    for i in range(y,L(m)-y):m[i][x]=m[i][w+~x]='|+'[m[i][x]>' ']
    return m


    Try it online!






    share|improve this answer









    $endgroup$





















      0












      $begingroup$


      Perl 6, 118 bytes





      {map ->y{map {' |-+'.comb[:2[map {$^b%%1*$b&&6>=$^a/($b+&-$b)%8>=2},$^x/¾,y/2,y,$x/3-$_]]},2..^$_*6},2..^$_*4}o*R**2


      Try it online!



      0-indexed. Returns a 2D array of characters. The basic idea is that the expression



      b = y & -y   // Isolate lowest one bit
      b <= x % (4*b) <= 3*b


      generates the pattern



      --- --- --- ---
      ----- -----
      --- --- --- ---
      ---------
      --- --- --- ---
      ----- -----
      --- --- --- ---


      Explanation



      { ... }o*R**2  # Feed $_=2**$n into block
      map ->y{ ... },2..^$_*4 # Map y=2..2**n*4-1
      map { ... },2..^$_*6 # Map $x=2..2**n*6-1
      ' |-+'.comb[:2[ ... ]] # Choose char depending on base-2 number from two Bools
      map { ... } # Map coordinates to Bool
      # Horizontal lines
      ,$^x/¾ # Modulo 8*¾=6
      ,y/2 # Skip every second row
      # Vertical lines
      ,y # Modulo 8
      ,$x/3 # Skip every third column
      -$_ # Empty middle column
      # Map using expression
      $^b%%1*$b&& # Return 0 if $b is zero or has fractional part
      6>=$^a/($b+&-$b)%8>=2 # Pattern with modulo 8





      share|improve this answer









      $endgroup$













        Your Answer





        StackExchange.ifUsing("editor", function () {
        return StackExchange.using("mathjaxEditing", function () {
        StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix) {
        StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
        });
        });
        }, "mathjax-editing");

        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "200"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f176521%2fascii-art-h-trees%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        7












        $begingroup$


        Canvas, 20 19 bytes



        ø⁸«╵[↷L⇵;l⇵└┌├-×╋‼│


        Try it here!



        Explanation:



        ø                    push an empty canvas
        ⁸«╵[ repeat input*2 + 1 times
        ↷ rotate clockwise
        L⇵ ceil(width/2)
        ;l⇵ ceil(height/2); leaves stack as [ ⌈½w⌉, canvas, ⌈½h⌉ ]
        └┌ reorder stack to [ canvas, ⌈½w⌉, ⌈½h⌉, ⌈½w⌉ ]
        ├ add 2 to the top ⌈w÷2⌉
        -× "-" * (2 + ⌈w÷2⌉)
        ╋ in the canvas, at (⌈w÷2⌉; ⌈h÷2⌉) insert the dashes
        ‼ normalize the canvas (the 0th iteration inserts at (0; 0) breaking things)
        │ and palindromize horizontally





        share|improve this answer











        $endgroup$


















          7












          $begingroup$


          Canvas, 20 19 bytes



          ø⁸«╵[↷L⇵;l⇵└┌├-×╋‼│


          Try it here!



          Explanation:



          ø                    push an empty canvas
          ⁸«╵[ repeat input*2 + 1 times
          ↷ rotate clockwise
          L⇵ ceil(width/2)
          ;l⇵ ceil(height/2); leaves stack as [ ⌈½w⌉, canvas, ⌈½h⌉ ]
          └┌ reorder stack to [ canvas, ⌈½w⌉, ⌈½h⌉, ⌈½w⌉ ]
          ├ add 2 to the top ⌈w÷2⌉
          -× "-" * (2 + ⌈w÷2⌉)
          ╋ in the canvas, at (⌈w÷2⌉; ⌈h÷2⌉) insert the dashes
          ‼ normalize the canvas (the 0th iteration inserts at (0; 0) breaking things)
          │ and palindromize horizontally





          share|improve this answer











          $endgroup$
















            7












            7








            7





            $begingroup$


            Canvas, 20 19 bytes



            ø⁸«╵[↷L⇵;l⇵└┌├-×╋‼│


            Try it here!



            Explanation:



            ø                    push an empty canvas
            ⁸«╵[ repeat input*2 + 1 times
            ↷ rotate clockwise
            L⇵ ceil(width/2)
            ;l⇵ ceil(height/2); leaves stack as [ ⌈½w⌉, canvas, ⌈½h⌉ ]
            └┌ reorder stack to [ canvas, ⌈½w⌉, ⌈½h⌉, ⌈½w⌉ ]
            ├ add 2 to the top ⌈w÷2⌉
            -× "-" * (2 + ⌈w÷2⌉)
            ╋ in the canvas, at (⌈w÷2⌉; ⌈h÷2⌉) insert the dashes
            ‼ normalize the canvas (the 0th iteration inserts at (0; 0) breaking things)
            │ and palindromize horizontally





            share|improve this answer











            $endgroup$




            Canvas, 20 19 bytes



            ø⁸«╵[↷L⇵;l⇵└┌├-×╋‼│


            Try it here!



            Explanation:



            ø                    push an empty canvas
            ⁸«╵[ repeat input*2 + 1 times
            ↷ rotate clockwise
            L⇵ ceil(width/2)
            ;l⇵ ceil(height/2); leaves stack as [ ⌈½w⌉, canvas, ⌈½h⌉ ]
            └┌ reorder stack to [ canvas, ⌈½w⌉, ⌈½h⌉, ⌈½w⌉ ]
            ├ add 2 to the top ⌈w÷2⌉
            -× "-" * (2 + ⌈w÷2⌉)
            ╋ in the canvas, at (⌈w÷2⌉; ⌈h÷2⌉) insert the dashes
            ‼ normalize the canvas (the 0th iteration inserts at (0; 0) breaking things)
            │ and palindromize horizontally






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 25 '18 at 15:52

























            answered Nov 25 '18 at 12:31









            dzaimadzaima

            14.6k21755




            14.6k21755























                7












                $begingroup$


                Charcoal, 22 bytes



                P-²FNF²«⟲T²+×⁺²κX²ι←‖O


                Try it online! Link is to verbose version of code. 0-indexed. Explanation:



                P-²


                Print the initial three -s, leaving the cursor in the middle.



                FN


                Repeat for the number of times given.



                F²«


                Repeat twice for each H. Each loop creates a slightly bigger H from the previous loop, but we only want alternate Hs.



                ⟲T²


                Rotate the figure.



                +×⁺²κX²ι←


                Draw half of the next line.



                ‖O


                Reflect to complete the step.



                The result at each iteration is as follows:



                ---

                | |
                +---+
                | |

                -+- -+-
                | |
                +-----+
                | |
                -+- -+-

                | | | |
                +-+-+ +-+-+
                | | | | | |
                | |
                +-------+
                | |
                | | | | | |
                +-+-+ +-+-+
                | | | |

                -+- -+- -+- -+-
                | | | |
                +--+--+ +--+--+
                | | | | | |
                -+- | -+- -+- | -+-
                | |
                +-----------+
                | |
                -+- | -+- -+- | -+-
                | | | | | |
                +--+--+ +--+--+
                | | | |
                -+- -+- -+- -+-





                share|improve this answer









                $endgroup$













                • $begingroup$
                  If you wonder how a 5-th level H looks like, a quick zoomed-out glance: i.imgur.com/EGapcrS.png
                  $endgroup$
                  – Paul
                  Nov 25 '18 at 17:59
















                7












                $begingroup$


                Charcoal, 22 bytes



                P-²FNF²«⟲T²+×⁺²κX²ι←‖O


                Try it online! Link is to verbose version of code. 0-indexed. Explanation:



                P-²


                Print the initial three -s, leaving the cursor in the middle.



                FN


                Repeat for the number of times given.



                F²«


                Repeat twice for each H. Each loop creates a slightly bigger H from the previous loop, but we only want alternate Hs.



                ⟲T²


                Rotate the figure.



                +×⁺²κX²ι←


                Draw half of the next line.



                ‖O


                Reflect to complete the step.



                The result at each iteration is as follows:



                ---

                | |
                +---+
                | |

                -+- -+-
                | |
                +-----+
                | |
                -+- -+-

                | | | |
                +-+-+ +-+-+
                | | | | | |
                | |
                +-------+
                | |
                | | | | | |
                +-+-+ +-+-+
                | | | |

                -+- -+- -+- -+-
                | | | |
                +--+--+ +--+--+
                | | | | | |
                -+- | -+- -+- | -+-
                | |
                +-----------+
                | |
                -+- | -+- -+- | -+-
                | | | | | |
                +--+--+ +--+--+
                | | | |
                -+- -+- -+- -+-





                share|improve this answer









                $endgroup$













                • $begingroup$
                  If you wonder how a 5-th level H looks like, a quick zoomed-out glance: i.imgur.com/EGapcrS.png
                  $endgroup$
                  – Paul
                  Nov 25 '18 at 17:59














                7












                7








                7





                $begingroup$


                Charcoal, 22 bytes



                P-²FNF²«⟲T²+×⁺²κX²ι←‖O


                Try it online! Link is to verbose version of code. 0-indexed. Explanation:



                P-²


                Print the initial three -s, leaving the cursor in the middle.



                FN


                Repeat for the number of times given.



                F²«


                Repeat twice for each H. Each loop creates a slightly bigger H from the previous loop, but we only want alternate Hs.



                ⟲T²


                Rotate the figure.



                +×⁺²κX²ι←


                Draw half of the next line.



                ‖O


                Reflect to complete the step.



                The result at each iteration is as follows:



                ---

                | |
                +---+
                | |

                -+- -+-
                | |
                +-----+
                | |
                -+- -+-

                | | | |
                +-+-+ +-+-+
                | | | | | |
                | |
                +-------+
                | |
                | | | | | |
                +-+-+ +-+-+
                | | | |

                -+- -+- -+- -+-
                | | | |
                +--+--+ +--+--+
                | | | | | |
                -+- | -+- -+- | -+-
                | |
                +-----------+
                | |
                -+- | -+- -+- | -+-
                | | | | | |
                +--+--+ +--+--+
                | | | |
                -+- -+- -+- -+-





                share|improve this answer









                $endgroup$




                Charcoal, 22 bytes



                P-²FNF²«⟲T²+×⁺²κX²ι←‖O


                Try it online! Link is to verbose version of code. 0-indexed. Explanation:



                P-²


                Print the initial three -s, leaving the cursor in the middle.



                FN


                Repeat for the number of times given.



                F²«


                Repeat twice for each H. Each loop creates a slightly bigger H from the previous loop, but we only want alternate Hs.



                ⟲T²


                Rotate the figure.



                +×⁺²κX²ι←


                Draw half of the next line.



                ‖O


                Reflect to complete the step.



                The result at each iteration is as follows:



                ---

                | |
                +---+
                | |

                -+- -+-
                | |
                +-----+
                | |
                -+- -+-

                | | | |
                +-+-+ +-+-+
                | | | | | |
                | |
                +-------+
                | |
                | | | | | |
                +-+-+ +-+-+
                | | | |

                -+- -+- -+- -+-
                | | | |
                +--+--+ +--+--+
                | | | | | |
                -+- | -+- -+- | -+-
                | |
                +-----------+
                | |
                -+- | -+- -+- | -+-
                | | | | | |
                +--+--+ +--+--+
                | | | |
                -+- -+- -+- -+-






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 25 '18 at 12:16









                NeilNeil

                79.9k744177




                79.9k744177












                • $begingroup$
                  If you wonder how a 5-th level H looks like, a quick zoomed-out glance: i.imgur.com/EGapcrS.png
                  $endgroup$
                  – Paul
                  Nov 25 '18 at 17:59


















                • $begingroup$
                  If you wonder how a 5-th level H looks like, a quick zoomed-out glance: i.imgur.com/EGapcrS.png
                  $endgroup$
                  – Paul
                  Nov 25 '18 at 17:59
















                $begingroup$
                If you wonder how a 5-th level H looks like, a quick zoomed-out glance: i.imgur.com/EGapcrS.png
                $endgroup$
                – Paul
                Nov 25 '18 at 17:59




                $begingroup$
                If you wonder how a 5-th level H looks like, a quick zoomed-out glance: i.imgur.com/EGapcrS.png
                $endgroup$
                – Paul
                Nov 25 '18 at 17:59











                1












                $begingroup$


                Python 2, 227 bytes





                L=len
                def f(n):
                if n==1:return[['-']*3]
                m=[l+[' ']*3+l for l in f(n-1)];w=L(m[0]);y=L(m)/2;x=w/4-1;m=map(list,m+[' '*w,' '*x+'-'*(w-x-x)+' '*x,' '*w]+m)
                for i in range(y,L(m)-y):m[i][x]=m[i][w+~x]='|+'[m[i][x]>' ']
                return m


                Try it online!






                share|improve this answer









                $endgroup$


















                  1












                  $begingroup$


                  Python 2, 227 bytes





                  L=len
                  def f(n):
                  if n==1:return[['-']*3]
                  m=[l+[' ']*3+l for l in f(n-1)];w=L(m[0]);y=L(m)/2;x=w/4-1;m=map(list,m+[' '*w,' '*x+'-'*(w-x-x)+' '*x,' '*w]+m)
                  for i in range(y,L(m)-y):m[i][x]=m[i][w+~x]='|+'[m[i][x]>' ']
                  return m


                  Try it online!






                  share|improve this answer









                  $endgroup$
















                    1












                    1








                    1





                    $begingroup$


                    Python 2, 227 bytes





                    L=len
                    def f(n):
                    if n==1:return[['-']*3]
                    m=[l+[' ']*3+l for l in f(n-1)];w=L(m[0]);y=L(m)/2;x=w/4-1;m=map(list,m+[' '*w,' '*x+'-'*(w-x-x)+' '*x,' '*w]+m)
                    for i in range(y,L(m)-y):m[i][x]=m[i][w+~x]='|+'[m[i][x]>' ']
                    return m


                    Try it online!






                    share|improve this answer









                    $endgroup$




                    Python 2, 227 bytes





                    L=len
                    def f(n):
                    if n==1:return[['-']*3]
                    m=[l+[' ']*3+l for l in f(n-1)];w=L(m[0]);y=L(m)/2;x=w/4-1;m=map(list,m+[' '*w,' '*x+'-'*(w-x-x)+' '*x,' '*w]+m)
                    for i in range(y,L(m)-y):m[i][x]=m[i][w+~x]='|+'[m[i][x]>' ']
                    return m


                    Try it online!







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 27 '18 at 9:14









                    TFeldTFeld

                    14.5k21241




                    14.5k21241























                        0












                        $begingroup$


                        Perl 6, 118 bytes





                        {map ->y{map {' |-+'.comb[:2[map {$^b%%1*$b&&6>=$^a/($b+&-$b)%8>=2},$^x/¾,y/2,y,$x/3-$_]]},2..^$_*6},2..^$_*4}o*R**2


                        Try it online!



                        0-indexed. Returns a 2D array of characters. The basic idea is that the expression



                        b = y & -y   // Isolate lowest one bit
                        b <= x % (4*b) <= 3*b


                        generates the pattern



                        --- --- --- ---
                        ----- -----
                        --- --- --- ---
                        ---------
                        --- --- --- ---
                        ----- -----
                        --- --- --- ---


                        Explanation



                        { ... }o*R**2  # Feed $_=2**$n into block
                        map ->y{ ... },2..^$_*4 # Map y=2..2**n*4-1
                        map { ... },2..^$_*6 # Map $x=2..2**n*6-1
                        ' |-+'.comb[:2[ ... ]] # Choose char depending on base-2 number from two Bools
                        map { ... } # Map coordinates to Bool
                        # Horizontal lines
                        ,$^x/¾ # Modulo 8*¾=6
                        ,y/2 # Skip every second row
                        # Vertical lines
                        ,y # Modulo 8
                        ,$x/3 # Skip every third column
                        -$_ # Empty middle column
                        # Map using expression
                        $^b%%1*$b&& # Return 0 if $b is zero or has fractional part
                        6>=$^a/($b+&-$b)%8>=2 # Pattern with modulo 8





                        share|improve this answer









                        $endgroup$


















                          0












                          $begingroup$


                          Perl 6, 118 bytes





                          {map ->y{map {' |-+'.comb[:2[map {$^b%%1*$b&&6>=$^a/($b+&-$b)%8>=2},$^x/¾,y/2,y,$x/3-$_]]},2..^$_*6},2..^$_*4}o*R**2


                          Try it online!



                          0-indexed. Returns a 2D array of characters. The basic idea is that the expression



                          b = y & -y   // Isolate lowest one bit
                          b <= x % (4*b) <= 3*b


                          generates the pattern



                          --- --- --- ---
                          ----- -----
                          --- --- --- ---
                          ---------
                          --- --- --- ---
                          ----- -----
                          --- --- --- ---


                          Explanation



                          { ... }o*R**2  # Feed $_=2**$n into block
                          map ->y{ ... },2..^$_*4 # Map y=2..2**n*4-1
                          map { ... },2..^$_*6 # Map $x=2..2**n*6-1
                          ' |-+'.comb[:2[ ... ]] # Choose char depending on base-2 number from two Bools
                          map { ... } # Map coordinates to Bool
                          # Horizontal lines
                          ,$^x/¾ # Modulo 8*¾=6
                          ,y/2 # Skip every second row
                          # Vertical lines
                          ,y # Modulo 8
                          ,$x/3 # Skip every third column
                          -$_ # Empty middle column
                          # Map using expression
                          $^b%%1*$b&& # Return 0 if $b is zero or has fractional part
                          6>=$^a/($b+&-$b)%8>=2 # Pattern with modulo 8





                          share|improve this answer









                          $endgroup$
















                            0












                            0








                            0





                            $begingroup$


                            Perl 6, 118 bytes





                            {map ->y{map {' |-+'.comb[:2[map {$^b%%1*$b&&6>=$^a/($b+&-$b)%8>=2},$^x/¾,y/2,y,$x/3-$_]]},2..^$_*6},2..^$_*4}o*R**2


                            Try it online!



                            0-indexed. Returns a 2D array of characters. The basic idea is that the expression



                            b = y & -y   // Isolate lowest one bit
                            b <= x % (4*b) <= 3*b


                            generates the pattern



                            --- --- --- ---
                            ----- -----
                            --- --- --- ---
                            ---------
                            --- --- --- ---
                            ----- -----
                            --- --- --- ---


                            Explanation



                            { ... }o*R**2  # Feed $_=2**$n into block
                            map ->y{ ... },2..^$_*4 # Map y=2..2**n*4-1
                            map { ... },2..^$_*6 # Map $x=2..2**n*6-1
                            ' |-+'.comb[:2[ ... ]] # Choose char depending on base-2 number from two Bools
                            map { ... } # Map coordinates to Bool
                            # Horizontal lines
                            ,$^x/¾ # Modulo 8*¾=6
                            ,y/2 # Skip every second row
                            # Vertical lines
                            ,y # Modulo 8
                            ,$x/3 # Skip every third column
                            -$_ # Empty middle column
                            # Map using expression
                            $^b%%1*$b&& # Return 0 if $b is zero or has fractional part
                            6>=$^a/($b+&-$b)%8>=2 # Pattern with modulo 8





                            share|improve this answer









                            $endgroup$




                            Perl 6, 118 bytes





                            {map ->y{map {' |-+'.comb[:2[map {$^b%%1*$b&&6>=$^a/($b+&-$b)%8>=2},$^x/¾,y/2,y,$x/3-$_]]},2..^$_*6},2..^$_*4}o*R**2


                            Try it online!



                            0-indexed. Returns a 2D array of characters. The basic idea is that the expression



                            b = y & -y   // Isolate lowest one bit
                            b <= x % (4*b) <= 3*b


                            generates the pattern



                            --- --- --- ---
                            ----- -----
                            --- --- --- ---
                            ---------
                            --- --- --- ---
                            ----- -----
                            --- --- --- ---


                            Explanation



                            { ... }o*R**2  # Feed $_=2**$n into block
                            map ->y{ ... },2..^$_*4 # Map y=2..2**n*4-1
                            map { ... },2..^$_*6 # Map $x=2..2**n*6-1
                            ' |-+'.comb[:2[ ... ]] # Choose char depending on base-2 number from two Bools
                            map { ... } # Map coordinates to Bool
                            # Horizontal lines
                            ,$^x/¾ # Modulo 8*¾=6
                            ,y/2 # Skip every second row
                            # Vertical lines
                            ,y # Modulo 8
                            ,$x/3 # Skip every third column
                            -$_ # Empty middle column
                            # Map using expression
                            $^b%%1*$b&& # Return 0 if $b is zero or has fractional part
                            6>=$^a/($b+&-$b)%8>=2 # Pattern with modulo 8






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 30 '18 at 11:31









                            nwellnhofnwellnhof

                            6,53511125




                            6,53511125






























                                draft saved

                                draft discarded




















































                                If this is an answer to a challenge…




                                • …Be sure to follow the challenge specification. However, please refrain from exploiting obvious loopholes. Answers abusing any of the standard loopholes are considered invalid. If you think a specification is unclear or underspecified, comment on the question instead.


                                • …Try to optimize your score. For instance, answers to code-golf challenges should attempt to be as short as possible. You can always include a readable version of the code in addition to the competitive one.
                                  Explanations of your answer make it more interesting to read and are very much encouraged.


                                • …Include a short header which indicates the language(s) of your code and its score, as defined by the challenge.



                                More generally…




                                • …Please make sure to answer the question and provide sufficient detail.


                                • …Avoid asking for help, clarification or responding to other answers (use comments instead).





                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f176521%2fascii-art-h-trees%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                mysqli_query(): Empty query in /home/lucindabrummitt/public_html/blog/wp-includes/wp-db.php on line 1924

                                How to change which sound is reproduced for terminal bell?

                                Can I use Tabulator js library in my java Spring + Thymeleaf project?