progs/mandelbrot.sc
changeset 491 e2ffe8642f55
parent 490 4778fefecd0c
child 493 244df77507c2
--- a/progs/mandelbrot.sc	Thu Jun 06 22:18:15 2024 +0100
+++ b/progs/mandelbrot.sc	Thu Jun 13 13:13:33 2024 +0100
@@ -3,30 +3,34 @@
 //
 //   see https://en.wikipedia.org/wiki/Mandelbrot_set
 //
-// needs to be called with
+// You can run on the file one the commandline with
 //
-//   scala-cli --extra-jars scala-parallel-collections_3-1.0.4.jar
+//   scala-cli mandelbrot.sc
 //
-// the jar-file is uploaded to KEATS
 //
 //
-// !! UPDATE ON TIMING: On my faster Mac-M1 machine 
-// !! the times for the first example are ca. 4 secs for 
-// !! the sequential version and around 0.7 secs for the 
+// !! UPDATE ON TIMING: On my faster Mac-M1 machine
+// !! the times for the first example are ca. 4 secs for
+// !! the sequential version and around 0.7 secs for the
 // !! par-version.
 
+// for parallel collections
+//> using dep org.scala-lang.modules::scala-parallel-collections:1.0.4
+import scala.language.implicitConversions
+import scala.collection.parallel.CollectionConverters.*
 
+// for graphics
 import javax.swing.{JFrame, JPanel, WindowConstants}
 import java.awt.{Color, Dimension, Graphics, Graphics2D}
 import java.awt.image.BufferedImage
 
-import scala.language.implicitConversions
-import scala.collection.parallel.CollectionConverters.*
+
+
 
 // complex numbers
-// represents the complex number re + im * i
+//   represents the complex number re + im * i
 case class Complex(val re: Double, val im: Double) {
-  
+
   def +(that: Complex) = Complex(this.re + that.re, this.im + that.im)
   def -(that: Complex) = Complex(this.re - that.re, this.im - that.im)
   def *(that: Complex) = Complex(this.re * that.re - this.im * that.im,
@@ -41,7 +45,8 @@
 // implicit conversion from Doubles to Complex
 given Conversion[Double, Complex] = Complex(_, 0)
 
-// some customn colours for the "sliding effect"
+// some customn colours for the "sliding effect" outside
+// the mandelbrot set
 val colours = List(
   Color(66, 30, 15),    Color(25, 7, 26),
   Color(9, 1, 47),      Color(4, 4, 73),
@@ -71,8 +76,8 @@
 
 // initialising the viewer panel
 def openViewer(width: Int, height: Int) : Viewer = {
+  val viewer = Viewer(width, height)
   val frame = JFrame("XYPlane")
-  val viewer = Viewer(width, height)
   frame.add(viewer)
   frame.pack()
   frame.setVisible(true)
@@ -116,7 +121,7 @@
 
      val c = start + x * d_x + y * d_y * i
      val iters = iterations(c, max)
-     val colour = 
+     val colour =
         if (iters == max) black
         else colours(iters % 16)
 
@@ -127,6 +132,8 @@
 }
 
 
+
+
 // Examples
 //==========
 
@@ -158,11 +165,9 @@
 
 //time_needed(mandelbrot(exc1, exc2, 1000))
 
-
-
 // some more computations with example 3
 
-val delta = (exc2 - exc1) * 0.0333
+val delta = (exc2 - exc1) * 0.01
 
 println(s"${time_needed(
   for (n <- (0 to 25))