Advertisement
Guest User

Untitled

a guest
Jul 27th, 2018
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 0.66 KB | None | 0 0
  1. #!/usr/bin/env scala
  2.  
  3. class Complex(val re: Double, val im: Double) {
  4.   override def toString = re + (if (im < 0) "-" else "+" + im) + "*i"
  5.   def add(c: Complex) = new Complex(re + c.re, im + c.im)
  6.   def mul(c: Complex) = new Complex(re * c.re - im * c.im, re * c.im + im * c.re)
  7. }
  8.  
  9. object MandelBrot extends App {
  10.   def mandelbrot(c: Complex, n: Int, z: Complex): Complex = {
  11.     if (n == 0) z
  12.     else
  13.       mandelbrot(c, n - 1, z.mul(z).add(c))
  14.   }
  15.  
  16.   val c = new Complex(0.04, 0.01)
  17.   val z0 = new Complex(0, 0)
  18.   val n = args(0).toInt
  19.   val debug = args(1) == "debug"
  20.   val z = mandelbrot(c, n, z0)
  21.   if (debug) println(z)
  22. }
  23.  
  24. MandelBrot.main(args)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement