This challenge consists in coding an interpreter for a Mondrian painting description language (MPDL).
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
Each command has the following format:
There are three commands:
v<integer> : 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<integer> : horizontal split. The top rectangle is pushed on the stack, then the bottom rectangle.
c<integer> : removes the latest rectangle from the stack and paints it to the color given as parameter. 1 = white, 2 = red, 3 = blue, 4 = yellow
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.
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: