Mondrian painting description language This challenge consists in coding an interpreter for a Mondrian painting description language (MPDL).

Language definition

The language operates on a stack of rectangles.
A rectangle is defined by its upper left coordinate and lower right coordinate. Coordinates must be integers.
The stack is initialized with a single rectangle with attributes (1,1,254,254)

Each command has the following format:
&lt;character&gt;&lt;integer&gt;

There are three commands:

v&lt;integer&gt; : perform a vertical split on the latest rectangle in the stack, at the position indicated by the parameter (as percentage). The source rectangle is removed from the stack and replaced with the two new rectangles that result of the split. The left rectangle is pushed on the stack, then the right rectangle. As rectangle coordinates are integers, fractions should be rounded to biggest smaller integer.

h&lt;integer&gt; : horizontal split. The top rectangle is pushed on the stack, then the bottom rectangle.

c&lt;integer&gt; : removes the latest rectangle from the stack and paints it to the color given as parameter. 1 = white, 2 = red, 3 = blue, 4 = yellow

Challenge

Write a program that takes as parameter a painting description and creates a 256x256 bitmap representation of the painted rectangles. The rectangles must be separated with a 3 pixel black line. A one or two pixel rectangle should have his non-black pixels hidden by the border black pixels. 

The input can be read as a parameter or as a file, up to you. The commands should be separated by a space. You can assume that the input file has correct syntax and does not have trailing or leading spaces, tabs, etc.
The output can be directly displayed on the screen, or saved to a file, up to you.

The shortest code wins.

Test

The following source:

v25 h71 v93 h50 c4 c1 c1 c2 h71 c3 h44 c1 c1


Should produce the Composition II in Red, Blue and Yellow:
Perl 5 + ImageMagick - 297

Something to start with:

sub a{my($x,$y,$X,$Y,$d)=@_;$_=shift@ARGV;
/v/?a($d=$x+($X-$x)*$'/100,$y,$X,$Y).a($x,$y,$d,$Y):
/h/?a($x,$d=$y+($Y-$y)*$'/100,$X,$Y).a($x,$y,$X,$d):
/c/&amp;&amp;"-fill ".qw/white red blue yellow/[$'-1]." -draw 'rectangle $x,$y $X,$Y' "}
system"convert -size 256x256 -stroke black xc: ".a(0,0,255,255)."a.gif"


Takes input on command line and generates a.gif.