val xmin = -2.0 val xmax = 1.0 val ymin = -1.0 val ymax = 1.0 fun escapes(cr: Double, ci: Double, it: Int): Boolean { var zr: Double = 0.0 var zi: Double = 0.0 var zrtmp: Double for(i in (1..it)) { // z <- z^2 + c zrtmp = zr*zr - zi*zi + cr zi = 2*zr*zi + ci zr = zrtmp if (zr*zr + zi*zi > 4) { return true } } return false } fun main(args: Array) { var xstep = args[0].toInt() var ystep = args[1].toInt() var iters = args[2].toInt() var x: Double var y: Double for(yc in 0..(ystep-1)) { y = yc*(ymax-ymin)/ystep + ymin for(xc in 0..(xstep-1)) { x = xc*(xmax-xmin)/xstep + xmin if (escapes(x, y, iters)) { print(' ') } else { print('X') } } print('\n') } }