15
\$\begingroup\$

What I would like to see is a fractal tree being drawn where the you can input an integer, and the output will be a fractal tree with the entered amount of branch steps.

Rules:

  • The fractal should be a line fractal tree: line fractal tree
  • the shape of the fractal should also be the same as this picture.
  • Each branch should decrease by 25% in width for each time it splits
  • The final layer of branches should be an 1px wide line
  • Shortest code wins

Tip: this site might be useful.

\$\endgroup\$
  • 2
    \$\begingroup\$ This question seems different enough from "Sorry, young man..." and I'm voting to reopen. For one, this doesn't require an L-system, and it is more precise in its description of the output. Answers to the other aren't necessarily the best answers here. \$\endgroup\$ – luser droog Jan 18 '14 at 22:09
  • \$\begingroup\$ If there's no new answers in the next day, I'll mark the shortest code as accepted. \$\endgroup\$ – joeytje50 Jan 23 '14 at 14:20
  • \$\begingroup\$ Can this tree be made with leaves ? \$\endgroup\$ – user45144 Sep 19 '15 at 15:59
  • \$\begingroup\$ @w4nteD The challenge of course does not specify any leaves, but I daresay they would be fairly easy to add to most of these programs. After the recursion decides to return, draw a leaf before returning. The current branch angle will be available for orientation. You could draw a leaf shape in the same direction, or maybe two at slight angles similar to the branching. \$\endgroup\$ – luser droog Sep 19 '15 at 17:30
12
\$\begingroup\$

Context Free, 82 65 57 characters

rule T{9*[y 1]SQUARE[]2*{f 90}T{s.75y 8r 25}}startshape T

A Tree

See: http://www.contextfreeart.org/gallery/view.php?id=3384

Golf'd further with help from Context Free Art users minimaleye, MtnViewJohn, and kipling.

\$\endgroup\$
  • \$\begingroup\$ According to a comment on that link you posted, it can be reduced to 64 characters. Nice one! \$\endgroup\$ – joeytje50 Jan 21 '14 at 15:19
  • 1
    \$\begingroup\$ Upvoting not only because it's a good answer with pretty output, but because I have never even heard of this language before. \$\endgroup\$ – Michael Stern Jan 21 '14 at 16:46
9
\$\begingroup\$

Python - 215

import turtle
t=turtle.Turtle()
def f(w):
    if w>=1:
        s=t.pensize()
        t.pensize(w)
        t.fd(w*9)
        t.rt(20)
        f(w*.75)
        t.lt(40)
        f(w*.75)
        t.right(20)
        t.bk(w*9)
        t.pensize(w)
t.speed(9)
f(9)
t.ht()
raw_input()

Close enough?
image

\$\endgroup\$
  • \$\begingroup\$ I'll accept it, because I just said that the "shape" should be the same. I didn't specify any orientation rules. \$\endgroup\$ – joeytje50 Jan 18 '14 at 0:15
  • \$\begingroup\$ a little more documentation (or at least meaningful names) could be very nice \$\endgroup\$ – Elisha Jan 19 '14 at 18:08
  • 2
    \$\begingroup\$ Documentation? This is a complete program. Run as-is, no arguments, no nothing. Meaningful names? You cannot fit a lot of meaning into 1 character, and last time I checked this is code-golf \$\endgroup\$ – mniip Jan 19 '14 at 18:49
  • \$\begingroup\$ I think "commentary" might be the word. I know that to a Python hacker, it must be very clear, and maybe to English-speakers who can recognize the abbreviated names, and turtle-graphics fans (like me) it is, but for others who don't know the language but want to vote you up, give them some help, you know? Tell a little story, even if it's just "the problem domain maps naturally to this feature set". Does that help?? I think that's what's going on here. ... Or at least, that's a practical way to interpret such comments. :) \$\endgroup\$ – luser droog Jan 22 '14 at 4:38
  • \$\begingroup\$ I think that n>=1 can be reduced to just n \$\endgroup\$ – Loovjo Sep 19 '15 at 19:19
9
\$\begingroup\$

Logo, 88, 86

to t:d if:d=0[stop]setpensize:d*.75 fd:d*7 rt 25 t:d-1 lt 50 t:d-1 rt 25 bk:d*7end t [numsteps]

Tree - size 11

Edit: Made the branches decrease as pointed out in the comments.

\$\endgroup\$
  • \$\begingroup\$ Your branches don't get shorter the further up the tree we go. This was one of the requirements, since "the shape of the fractal should also be the same as this picture". Also, you should include the code to create the tree in the character count. Other than that, well done on the short code! \$\endgroup\$ – joeytje50 Jan 19 '14 at 18:14
  • \$\begingroup\$ Also, your branch width isn't decreasing geometrically at 25% each time - it's linear based on the iteration number. I set my pen size to (4/3)^(:d-1) to accomplish this. The lowest I got in my Logo attempt was 108. Nice work! \$\endgroup\$ – GuitarPicker Aug 13 '16 at 6:44
9
\$\begingroup\$

Mathematica 127

k=12;

r=#2/.{x__Real}:>.1{{7,-#},{#,7}}.{x}+y&;
f@n_:={f@1=N@Polygon@{y={0,.7^k},0y,x={.002,0},x+y},r[-4,p=f[n-1]],4~r~p}
Graphics@f@k

enter image description here

Value .002 adjusted to produce 1 pixel width of the final branches.

\$\endgroup\$
8
\$\begingroup\$

HTML+CSS (no JavaScript) 14791 14630 (multiplatform), 294 (webkit only)

You can't specify how many levels you go.. And yes it is pretty big. But it is pure HTML/CSS, without any JavaScript.

<style>q{background-color:#000}q::before{content:""}q.start{width:15px;height:100px;position:absolute;top:500px;left:500px}q q{position:absolute;width:75%;height:75%;top:-55%}q q:nth-child(1){left:-90%;transform:rotate(-27deg)}q q:nth-child(2){left:110%;transform:rotate(27deg)}</style><q class="start"><q><q><q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q></q><q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q></q></q><q><q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q></q><q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q></q></q></q> <q><q><q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q></q><q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q></q></q><q><q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q></q><q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q><q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q><q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q><q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q><q><q><q><q></q><q></q></q><q><q></q><q></q></q></q><q><q><q></q><q></q></q><q><q></q><q></q></q></q></q></q></q></q></q></q></q></q>

Webkit short version:

<style>b{background:#000;-webkit-box-reflect: left;}b.i{width:7px;height:100px;position:absolute;top:500px;left:500px}b b{position:absolute;width:75%;height:75%;top:-70%}b b{right:300%;transform:rotate(-27deg)}</style><b class="i"><b><b><b><b><b><b><b><b></b><b></b></b></b></b></b></b></b></b>

Fractaltree
Edit: removed the cross browser prefixes, firefox and google chrome render it properly without it. Edit 2: Added a much shorter version that uses -webkit-box-reflect. Only works in webkit based browsers though.

\$\endgroup\$
  • \$\begingroup\$ <style>q{background-color:#000}q::before{content:""}q.start{width:15px;height:100px;position:absolute;top:500px;left:500px}q q{position:absolute;width:75%;height:75%;top:-55%}q q:nth-child(1){left:-90%;transform:rotate(-27deg)}q q:nth-child(2){left:110%;transform:rotate(27deg)}</style><q class="start"><q></q><q></q></q> With only three branches and removing non needed CSS components for cross-browser compatibility the code is 321 characters long. Adding a level of branches is done by replacing <q></q> with <q><q></q><q></q></q>. \$\endgroup\$ – Jim Bauwens Sep 26 '14 at 18:01
  • \$\begingroup\$ Ha, this got an "excessively long" automatic flag. :D It would be interesting if you posted the code to generate this (or explain how you did it). (Assuming you didn't do it by hand!) \$\endgroup\$ – Doorknob Sep 26 '14 at 21:11
  • \$\begingroup\$ Doorknob: The core CSS code that does the real 'magic' is in the beginning, it 'recursivly' positions sub HTML in the correct way using transforms, such that they form the tree. The HTML itself I did manually, but isn't hard. I start with <q></q> and use my code editor to replace that with <q><q></q><q></q></q>. Every time I repeat this replacement operation I add a level of branches to my fractal. The CSS automatically wil render the added levels correctly. My previous comment demonstrates this. \$\endgroup\$ – Jim Bauwens Sep 27 '14 at 10:24
7
\$\begingroup\$

Mathematica 199

f[p : {_, _}, r_, s_, d_] := Module[{q}, If[d == 0, Return[]];
  q = p + {Cos@r, Sin@r}*d;
  DeleteCases[
   Flatten@{{Thickness[.002*1.25^d], Line@{p, q}}, 
     f[q, r - s, s, d - 1], f[q, r + s, s, d - 1]}, Null]]
g@d_ := Graphics[f[{0, 0}, Pi/2, Pi/9, d]]

Example

8 is the depth of the tree.

g[8]

tree

\$\endgroup\$
6
\$\begingroup\$

Postscript 216 214 209

Uses the criteria "linewidth==1 pixel" as the recursion bound. Edit: juggled some constants. Edit: tweak, tweak.

/b{gsave dup scale rotate
0 0 0 12 0 0 moveto translate lineto stroke
currentlinewidth 0 dtransform dup mul exch dup mul add sqrt 1 ge
{28 .75 b -28 .75 b}if grestore}def
2 setlinewidth
200 20 translate
0 6 b

binary-token workfile:

0 6 200 20 2
/.{<920>dup 1 4 3 roll put cvx exec}def/${//. 73 .}def
%/b{gsave dup scale rotate  % gsave=78(N)<4E> dup=56(8)<38> scale=139<8B> rotate=136<88>
/b{
%(N8)$<8B88>$
<4E388B88>$
0 0 0 12 0 0
%moveto translate lineto stroke
% moveto=107(k)<6B> lineto=99(c)<63> translate=173<AD> stroke=167<A7>
%(k)$<AD>$(c)$<A7>$
%<6B63ADA7>$ % <--this typo makes a pot leaf. :-)
<6BAD63A7>$
%currentlinewidth 0 dtransform % clw=38(&) dxfm=55(7)
0(&7)$
%dup mul exch dup mul add sqrt 1 ge % mul=108 sqrt=355 ge=74 add=1 exch=62
(8l>8l)$ add sqrt 1 ge
{28 .75 b -28 .75 b}
%if grestore}def % grestore=77(M) if=84(T) def=51(3)<33>
(TM)$
}
%(3)$
%setlinewidth % slw=155<9B>
%translate % trsl8=173<AD>
<339BAD>$ b

Postscript 172 169

Same program using binary token strings.

/.{<920>dup 1 4 3 roll put cvx exec}def/${//. 73 .}def
0 6 200 20 2/b{<4E388B88>$ 0 0 0 12 0 0<6BAD63A7>$
0(&78l>8l)$ add sqrt 1 ge{28 .75 b -28 .75 b}(TM)$}<339BAD>$
b

output2

\$\endgroup\$
1
\$\begingroup\$

CoffeeScript (using Canvas) (289 bytes)

enter image description here

The following creates branches until the pixel width is less than 1px. The width and height of the image created is 500px. To see the virtual image that the program draws, add document.body.appendChild(c) to the last line of the code.

c=document.createElement 'canvas'
c.width=c.height=500
t=c.getContext '2d'
m=Math
b=m.PI/8
f=(w,l,x,y,a)->
    t.beginPath()
    t.moveTo x,y
    X=x+m.cos(a)*l
    Y=y+m.sin(a)*l
    t.lineWidth=w
    t.lineTo X,Y
    t.stroke()
    if w >= 1
        f w*3/4,l*3/4,X,Y,a+b
        f w*3/4,l*3/4,X,Y,a-b
f 10,90,250,0,m.PI/2
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.