Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env scala
- class Complex(val re: Double, val im: Double) {
- override def toString = re + (if (im < 0) "-" else "+" + im) + "*i"
- def add(c: Complex) = new Complex(re + c.re, im + c.im)
- def mul(c: Complex) = new Complex(re * c.re - im * c.im, re * c.im + im * c.re)
- }
- object MandelBrot extends App {
- def mandelbrot(c: Complex, n: BigInt, z: Complex): Complex = {
- if (n == 0) z
- else
- mandelbrot(c, n - 1, z.mul(z).add(c))
- }
- val c = new Complex(0.04, 0.01)
- val z0 = new Complex(0, 0)
- val n = BigInt(args(0))
- val debug = args(1) == "debug"
- val z = mandelbrot(c, n, z0)
- if (debug) println(z)
- }
- MandelBrot.main(args)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement