diff -r f211d9cb856e -r 4d300409f2fe progs/mandelbrot.scala --- a/progs/mandelbrot.scala Fri Jun 22 13:34:05 2018 +0100 +++ b/progs/mandelbrot.scala Tue Jun 26 01:49:32 2018 +0100 @@ -1,3 +1,6 @@ +// Mandelbrot pictures +// see https://en.wikipedia.org/wiki/Mandelbrot_set + import java.awt.Color import java.awt.Dimension import java.awt.Graphics @@ -19,9 +22,10 @@ def abs() = Math.sqrt(this.re * this.re + this.im * this.im) } +// to allow the notation n + m * i object i extends Complex(0, 1) +implicit def double2complex(re: Double) = Complex(re, 0) -implicit def double2complex(re: Double): Complex = Complex(re, 0) // some customn colours for the "sliding effect" val colours = List( @@ -84,6 +88,8 @@ } // main function +// start and end are the upper-left and lower right corners +// max is the number of maximum iterations def mandelbrot(start: Complex, end: Complex, max: Int) : Unit = { viewer.clearCanvas(black) @@ -91,8 +97,8 @@ val d_x = (end.re - start.re) / W val d_y = (end.im - start.im) / H - for (y <- (0 until H).par) { - for (x <- (0 until W).par) { + for (y <- (0 until H)) { + for (x <- (0 until W)) { val c = start + (x * d_x + y * d_y * i) @@ -107,6 +113,7 @@ } } + // Examples //==========