[Question]
  [
...so this is a challenge to make me a tree.
Produce a program or function called tree which takes a single integer argument, N and draws a Pythagorean Tree N levels deep, where level 0 is just the trunk.
Each junction of the tree should place the vertex of the triangle at a random point on the perimeter (this point should be uniformly distributed over at least 5 equally spaced points, or uniformly over the whole semicircle).
Optionally your tree may be 3d, be colourful, or be lit according to the time of day. However, this is code-golf, so the smallest file wins.
EDIT: I'll shut the contest and accept the smallest answer when it's a week old
  
[Answer]
## CFDG, 134 characters
This one isn't exactly valid, because you cannot limit the recursion depth. But the problem just calls for a solution in [this one](http://www.contextfreeart.org/). :)
```
startshape t
c(q)=cos(q/2)^2
d(q)=1+sin(q)/2
p=acos(-1)
shape t{w=rand(p)
SQUARE[x .5 .5]t[trans 0 1 c(w) d(w)]t[trans c(w) d(w) 1 1]}
```
The results look something like this
![enter image description here](https://i.stack.imgur.com/ATY6Y.png)
For another 46 characters (**180 characters** in total), you can even colour it in:
```
startshape t
c(q)=cos(q/2)^2
d(q)=1+sin(q)/2
p=acos(-1)
shape t{w=rand(p)
SQUARE[x .5 .5 h 25 sat 1 b .2]t[trans 0 1 c(w) d(w) b .08 .8 h 2.2]t[trans c(w) d(w) 1 1 b .08 .8 h 2.2]}
```
![enter image description here](https://i.stack.imgur.com/4YLsb.png)
[Answer]
## Mathematica, ~~246~~ ~~234~~ 221 characters
```
g[n_,s_:1]:={p=RandomReal[q=Pi/2],r=##~Rotate~(o={0,0})&,t=Translate}~With~If[n<0,{},Join[#~t~{0,s}&/@(#~r~p&)/@g[n-1,s*Cos@p],t[#,s{Cos@p^2,1+Sin[2p]/2}]&/@(r[#,p-q]&)/@g[n-1,s*Sin@p],{Rectangle[o,o+s]}]]
f=Graphics@g@#&
```
This is certainly not the most elegant/shortest way to do this.
Usage: `f[8]`
![enter image description here](https://i.stack.imgur.com/J8QbG.png)
And here are example outputs for `f[6]` and `f[10]` respectively.
![enter image description here](https://i.stack.imgur.com/8ER8H.png)
![enter image description here](https://i.stack.imgur.com/910OS.png)
Somewhat ungolfed:
```
g[n_, s_:1] := With[{p},
  r = Rotate;
  t = Translate;
  p = RandomReal[q = Pi/2];
  If[n < 0, {},
   Join[
    (t[#, {0, s}] &) /@ (r[#, p, {0, 0}] &) /@ g[n - 1, s*Cos[p]],
    (t[#, s {Cos[p]^2, 1 + Sin[2 p]/2}] &) /@ (r[#, p - q, {0, 0}] &) /@
       g[n - 1, s*Sin[p]],
    {Rectangle[{0, 0}, {s, s}]}
    ]
   ]
  ]
f = Graphics@g[#] &
```
[Answer]
## Mathematica, 122 characters
```
Graphics[Polygon/@ReIm@NestList[Join@@({##3}+Cos[t=Random[]Pi/2]E^(I t){I Tan@t(#2-{##}),{##}-#}&)@@@#&,{{0,1,1+I,I}},#]]&
```
[![enter image description here](https://i.stack.imgur.com/N56MK.png)](https://i.stack.imgur.com/N56MK.png)
Ungolfed version:
```
Clear["`*"];
next=Compile[{{z,_Complex,1},t},{z[[4]]-E^(I t) (z[[1]]-z) Cos[t],z[[3]]+I E^(I t) (z[[2]]-z) Sin[t]},RuntimeAttributes->{Listable}];
n=15;
list=ReIm@NestList[next[#,Random[]Pi/2]&,N@{{0,1,1+I,I}},n];
poly=MapIndexed[With[{i=Tr@#2},{ColorData["Rainbow",i/(n+1)],Polygon@Flatten[#,i-1]}]&,list];
Graphics[{Antialiasing->True,poly},PlotRange->{{-7,7},{-1,10}},ImageSize->Large,Background->Black]
```
[![enter image description here](https://i.stack.imgur.com/drxO4.gif)](https://i.stack.imgur.com/drxO4.gif)
3D version, refer to <https://mathematica.stackexchange.com/questions/213727/how-to-draw-a-pythagoras-tree-like-this/213827#213827>, render by POV-Ray
[![enter image description here](https://i.stack.imgur.com/rMQpd.png)](https://i.stack.imgur.com/rMQpd.png)
[Answer]
# Coffeescript ~~377B~~ 352B
I feel dirty writing coffeescript but I can't find a decent drawing package for python3 :-/
```
Q=(n)->X=(D=document).body.appendChild(C=D.createElement('Canvas')).getContext('2d');C.width=C.height=400;M=Math;T=[[175,400,50,i=0]];S=M.sin;C=M.cos;while [x,y,l,a]=T[i++]
 X.save();X.translate x,y;X.rotate -a;X.fillRect 0,-l,l,l;X.restore();T.push [e=x-l*S(a),f=y-l*C(a),g=l*C(b=M.random()*M.PI/2),d=a+b],[e+g*C(d),f-g*S(d),l*S(b),d-M.PI/2] if i<2**n
```
# Javascript ~~393B~~ 385B
Slightly prettier in javascript and I'm much happier with the for-loop but without the [x,y,z]=A syntax I just can't make it short enough to beat coffeescript
```
function Q(n){X=(D=document).body.appendChild(C=D.createElement('Canvas')).getContext('2d');C.width=C.height=600;M=Math;T=[[275,400,50,i=0]];while(A=T[i++]){X.save();X.translate(x=A[0],y=A[1]);X.rotate(-(a=A[3]));X.fillRect(0,-(l=A[2]),l,l);X.restore();S=M.sin;C=M.cos;i<M.pow(2,n)&&T.push([e=x-l*S(a),f=y-l*C(a),g=l*C(b=M.random()*M.PI/2),d=a+b],[e+g*C(d),f-g*S(d),l*S(b),d-M.PI/2])}}
```
Got to say I'm a bit galled this is almost twice as long as the mathematica solution :-/ see it in action: <http://jsfiddle.net/FK2NX/3/>
[Answer]
## Postscript, ~~322~~ 270
**Edit:** It appears that `realtime` can't be used as proper random generator seed. Therefore, we'll use environment variable for this purpose and run the program like that:
```
gs -c 20 $RANDOM -f tree.ps
```
or
```
gswin32c -c 20 %RANDOM% -f tree.ps
```
Now our trees are less predictable. 14 bytes are added to total count. Other changes: 1) Program argument is now passed on command line. 2) No explicit iteration counter - stack size serves for this purpose (left branch rotation angle is stored on stack, to draw right branch, later). 3) There's no named variable for required depth - stack size is its offset, on stack. It's left there on exit, i.e. it is not consumed.
```
srand
250 99 translate
50 50 scale
/f{
    count
    dup index div dup 1 le{
        0 exch 0 setrgbcolor
        0 0 1 1 rectfill
        0 1 translate
        rand 5 mod 1 add 15 mul
        gsave
        dup rotate
        dup cos dup scale
        f
        grestore
        dup cos dup dup mul
        exch 2 index sin mul translate
        dup 90 sub rotate
        sin dup scale 1
        f
        pop
    }{pop}ifelse
}def
f
```
I think it's pretty obvious - graphics state is prepared and `f` procedure is called recursively for each consecutive level of depth, twice - for 'left' and 'right' branches. Working with rectangle of `1x1` size (see original scale) saves the trouble of multiplying by side length. Angle of rotation of left branch is randomized - one of 5 random equally spaced divisions is used - I think it prevents possible ugly cases for uniform randomness.
It might be slow for required depth of more than 20 or so. 
Next is golfed version, using ASCII-encoded binary tokens (see luser droog's answer from linked topic). Note, `cos`, `sin`, `rand` can not use this notation. 
```
/${{<920>dup 1 4 3 roll put cvx exec}forall}def srand 250 99<AD>$ 50 50<8B>$/f{count(8X68)$ 1 le{0(>)$ 0<9D>$ 0 0 1 1<80>$ 0 1<AD>$ rand 5 mod 1 add 15<~CecsG2u~>$ cos<388B>$ f(M8)$ cos(88l>)$ 2(X)$ sin<6CAD38>$ 90<A988>$ sin<388B>$ 1 f pop}{pop}(U)$}def f
```
.
```
/${{<920>dup 1 4 3 roll put cvx exec}forall}def
srand
250 99<AD>$
50 50<8B>$
/f{
count(8X68)$
1 le{
0(>)$ 0<9D>$
0 0 1 1<80>$
0 1<AD>$
rand 5 mod 1 add 15 
<~CecsG2u~>$
cos<388B>$ 
f
(M8)$
cos(88l>)$
2(X)$ sin<6CAD38>$
90<A988>$ sin<388B>$
1
f
pop
}{pop}(U)$
}def
f
```
![enter image description here](https://i.stack.imgur.com/peGsG.png)
]