Draw A Sierpinski Triangle The Sierpinsky Triangle is a fractal created by taking a triangle, decreasing the height and width by 1/2, creating 3 copies of the resulting triangle, and place them such each triangle touches the other two on a corner.  This process is repeated over and over again with the resulting triangles to produce the Sierpinski triangle, as illustrated below.



Write a program to generate a Sierpinski triangle.  You can use any method you want to generate the pattern, either by drawing the actual triangles, or by using a random algorithm to generate the picture.  You can draw in pixels, ascii art, or whatever you want, so long as the output looks similar to the last picture shown above.  Fewest characters wins.
HTML + JavaScript, 150 characters (see notes for 126 characters)

Whitespace inserted for readability and not counted.

&lt;title&gt;&lt;/title&gt;&lt;canvas&gt;&lt;/canvas&gt;&lt;script&gt;
for(x=k=128;x--;)for(y=k;y--;)
  x&amp;y||document.body.firstChild.getContext("2d").fillRect(x-~y/2,k-y,1,1)
&lt;/script&gt;


The core of it is applying the rule of coloring pixels for which x &amp; y == 0 by the conditional x&amp;y||, which produces a “Sierpinski right triangle”; and x-~y/2,k-y are a coordinate transformation to produce the approximately equilateral display.



A less correct (HTML-wise) version is 126 characters:

&lt;canvas&gt;&lt;script&gt;
for(x=k=128;x--;)for(y=k;y--;)
  x&amp;y||document.body.firstChild.getContext("2d").fillRect(x-~y/2,k-y,1,1)
&lt;/script&gt;


(The way in which this is less correct is that it omits the title element and the end tag of the canvas element, both of which are required for a correct document even though omitting them does not change the interpretation of the document.)

Three characters can be saved by eliminating k in favor of the constant 64, at the cost of a smaller result; I wouldn't count the 8 option as it has insufficient detail.

Note that a size of 256 or higher requires attributes on the &lt;canvas&gt; to increase the canvas size from the default.