Create a fractal tree

15

5

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.

joeytje50

Posted 2014-01-17T23:59:46.310

Reputation: 573

Can this tree be made with leaves ? – None – 2015-09-19T15:59:07.860

@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. – luser droog – 2015-09-19T17:30:21.357

2This 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. – luser droog – 2014-01-18T22:09:53.893

If there's no new answers in the next day, I'll mark the shortest code as accepted. – joeytje50 – 2014-01-23T14:20:26.617

Answers

12

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.

MtnViewMark

Posted 2014-01-17T23:59:46.310

Reputation: 4 779

According to a comment on that link you posted, it can be reduced to 64 characters. Nice one! – joeytje50 – 2014-01-21T15:19:13.560

1Upvoting not only because it's a good answer with pretty output, but because I have never even heard of this language before. – Michael Stern – 2014-01-21T16:46:15.370

9

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

mniip

Posted 2014-01-17T23:59:46.310

Reputation: 9 396

I think that n>=1 can be reduced to just n – Loovjo – 2015-09-19T19:19:33.333

How fitting that you used the turtle library for a fractal problem :) – Christopher Wirt – 2016-06-10T21:50:24.380

I'll accept it, because I just said that the "shape" should be the same. I didn't specify any orientation rules. – joeytje50 – 2014-01-18T00:15:56.590

a little more documentation (or at least meaningful names) could be very nice – Elisha – 2014-01-19T18:08:13.537

2Documentation? 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 [tag:code-golf] – mniip – 2014-01-19T18:49:12.787

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. :) – luser droog – 2014-01-22T04:38:50.493

9

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.

Gabriele D'Antona

Posted 2014-01-17T23:59:46.310

Reputation: 1 336

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! – GuitarPicker – 2016-08-13T06:44:26.530

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! – joeytje50 – 2014-01-19T18:14:19.307

9

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.

ybeltukov

Posted 2014-01-17T23:59:46.310

Reputation: 1 841

8

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.

Jim Bauwens

Posted 2014-01-17T23:59:46.310

Reputation: 81

<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>. – Jim Bauwens – 2014-09-26T18:01:20.957

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!) – Doorknob – 2014-09-26T21:11:18.077

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. – Jim Bauwens – 2014-09-27T10:24:51.033

7

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

DavidC

Posted 2014-01-17T23:59:46.310

Reputation: 24 524

6

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

luser droog

Posted 2014-01-17T23:59:46.310

Reputation: 4 535

1

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

robert

Posted 2014-01-17T23:59:46.310

Reputation: 111