Mondrian-Maker

I continued in my love of Mondrian that I shared yesterday to make a jsfiddle that is capable of making Mondrian's at will. I am fairly certain that if you click it enough you will eventually be able to re-create all of the works of Mondrian (or at least all of them on square canvases). There are still some bugs in the program that I do not feel like working out. I noticed that there are no 'L'-shaped blocks in Mondrian's work, and I tried to eliminate that feature, but somehow just could not get it to work until I stopped caring.

The basic architecture of the program was to make horizontal and vertical lines, then create squares from the vertices. I made one routine, makeLines, to set up all of the lines with a random number generator. After the lines were drawn, I stored their positions in two matrices. I then found all of the vertices, including those starting on the edges of the drawing. The final step was drawing squares, and they should also have a degree of randomness to them. I set the color and size at random, while using the customary colors of red, yellow, and blue. White tends to be more prominent, so I generated white more often.

I found that creating squares that started and ended at vertices was somewhat tricky. I ultimately figured out a good way to achieve this by choosing a random number for the horizontal and vertical directions and making the square go 1-3 lengths in either direction.

The final result works, except for those pesky 'L'-shaped designs, oh well. The final fiddle can be found here, as well as below.