progs/mandelbrot.scala
changeset 464 73ced118f73d
parent 444 7a0735db4788
child 470 86a456f8cb92
--- a/progs/mandelbrot.scala	Sat Mar 11 22:01:53 2023 +0000
+++ b/progs/mandelbrot.scala	Sat Mar 11 22:42:09 2023 +0000
@@ -3,9 +3,14 @@
 //
 //   see https://en.wikipedia.org/wiki/Mandelbrot_set
 // 
-// under scala 2.13.XX needs to be called with
+// under scala 3.2.2 needs to be called with
 // 
-// scala -cp scala-parallel-collections_2.13-0.2.0.jar mandelbrot.scala
+// scala -cp scala-parallel-collections_3-1.0.4.jar
+//
+// !! UPDATE: On my faster Mac-M1 machine the times
+// !! are ca. 4 secs for the sequential version and
+// !! around 0.7 secs for the par-version.
+
 
 import java.awt.Color
 import java.awt.Dimension
@@ -31,7 +36,9 @@
 
 // to allow the notation n + m * i
 object i extends Complex(0, 1)
-implicit def double2complex(re: Double) = Complex(re, 0)
+
+// implicit conversion from Doubles to Complex
+given Conversion[Double, Complex] = Complex(_, 0)
 
 
 // some customn colours for the "sliding effect"
@@ -104,17 +111,17 @@
   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)
      val iters = iterations(c, max) 
-     val col = 
+     val colour = 
        if (iters == max) black 
        else colours(iters % 16)
 
-     pixel(x, y, col)
+     pixel(x, y, colour)
     }
     viewer.updateUI()
   }