/*
* Starting code for MCS-178 Assignment: Mondrian Art
*
* Generate and output a Mondrian-style image
* as an SVG tag within an HTML document.
*/
const val WIDTH = 1024 // width of the image being generated
const val HEIGHT = 768 // height of the image being generated
const val SPLIT_LIMIT = 120 // don't split if length < 120
val randGen = java.util.Random()
/*
* Select a color so that the odd for white is 3 to 1,
* and the other colors being equally likely.
*/
fun randomColor() = when (randGen.nextInt(12)) {
0 -> "red"
1 -> "skyblue"
2 -> "yellow"
else -> "white"
}
/* Return a random integer between 33% and 66% of 'length' inclusive */
fun randomMiddleThird(length: Int) =
((33 + randGen.nextInt(34)) / 100.0 * length).toInt()
/*
* This function currently generates one SVG tag for a rectangle
* with a random color. You task is to replace the implementation
* of this function so that it generates all of the tags needed
* for a piece of random Mondrian art. You may write additional
* helper functions to accomplish this task.
*
* Parameters:
* x, y: The upper left corner of the region
* w, h: The width and height of the region
*
* Returns:
* String: The SVG tags that draw the image
*/
fun mondrian(x: Int, y: Int, w: Int, h: Int): String {
return "\n"
}
/* The main function generates and outputs the file 'mondrian.html'. */
fun main(args: Array) {
val outputString = arrayOf(
"\n\n\n\n"
)
java.io.PrintWriter("mondrian.html").use {
for (str in outputString)
it.append("$str")
}
}