1 // Mandelbrot pictures |
1 // Mandelbrot pictures |
2 //===================== |
2 //===================== |
3 // |
3 // |
4 // see https://en.wikipedia.org/wiki/Mandelbrot_set |
4 // see https://en.wikipedia.org/wiki/Mandelbrot_set |
5 // |
5 // |
6 // You can run on the file one the commandline with |
6 // You can run the file on the commandline with |
7 // |
7 // |
8 // scala mandelbrot.sc |
8 // scala mandelbrot.sc |
9 // |
9 // |
|
10 // Or inside the REPL with |
10 // |
11 // |
|
12 // scala --extra-jars scala-parallel-collections_3-1.0.4.jar |
11 // |
13 // |
12 // !! UPDATE ON TIMING: On my faster Mac-M1 machine |
14 // !! UPDATE ON TIMING: On my faster Mac-M1 machine |
13 // !! the times for the first example are ca. 4 secs for |
15 // !! the times for the first example are ca. 4 secs for |
14 // !! the sequential version and around 0.7 secs for the |
16 // !! the sequential version and around 0.7 secs for the |
15 // !! par-version. |
17 // !! par-version. |
16 |
18 |
17 // for parallel collections |
19 // for parallel collections |
18 //> using dep org.scala-lang.modules::scala-parallel-collections:1.0.4 |
20 //> using dep org.scala-lang.modules::scala-parallel-collections:1.0.4 |
19 import scala.language.implicitConversions.* |
|
20 import scala.collection.parallel.CollectionConverters.* |
21 import scala.collection.parallel.CollectionConverters.* |
21 |
22 |
22 // for graphics |
23 // for graphics |
23 import javax.swing.{JFrame, JPanel, WindowConstants} |
24 import javax.swing.{JFrame, JPanel, WindowConstants} |
24 import java.awt.{Color, Dimension, Graphics, Graphics2D} |
25 import java.awt.{Color, Dimension, Graphics, Graphics2D} |
175 for (n <- (0 to 25)) |
176 for (n <- (0 to 25)) |
176 mandelbrot(exc1 + delta * n, |
177 mandelbrot(exc1 + delta * n, |
177 exc2 - delta * n, 1000))} secs") |
178 exc2 - delta * n, 1000))} secs") |
178 |
179 |
179 |
180 |
180 |
|
181 // Larry Paulson's example |
181 // Larry Paulson's example |
182 val exl1 = -0.74364990 + 0.13188170 * i |
182 val exl1 = -0.74364990 + 0.13188170 * i |
183 val exl2 = -0.74291189 + 0.13261971 * i |
183 val exl2 = -0.74291189 + 0.13261971 * i |
184 |
184 |
185 //println(s"${time_needed(mandelbrot(exl1, exl2, 1000))} secs") |
185 //println(s"${time_needed(mandelbrot(exl1, exl2, 1000))} secs") |