equal
  deleted
  inserted
  replaced
  
    
    
|      3 // |      3 // | 
|      4 //   see https://en.wikipedia.org/wiki/Mandelbrot_set |      4 //   see https://en.wikipedia.org/wiki/Mandelbrot_set | 
|      5 //  |      5 //  | 
|      6 // needs to be called with |      6 // needs to be called with | 
|      7 //  |      7 //  | 
|      8 // scala -cp scala-parallel-collections_3-1.0.4.jar |      8 // scala-cli --extra-jars scala-parallel-collections_3-1.0.4.jar | 
|         |      9 // | 
|         |     10 // the library is also uploaded to KEATS  | 
|      9 // |     11 // | 
|     10 // !! UPDATE: On my faster Mac-M1 machine the times |     12 // !! UPDATE: On my faster Mac-M1 machine the times | 
|     11 // !! are ca. 4 secs for the sequential version and |     13 // !! are ca. 4 secs for the sequential version and | 
|     12 // !! around 0.7 secs for the par-version. |     14 // !! around 0.7 secs for the par-version. | 
|     13  |     15  | 
|     90 // draw a pixel on the canvas |     92 // draw a pixel on the canvas | 
|     91 def pixel(x: Int, y: Int, color: Color) =  |     93 def pixel(x: Int, y: Int, color: Color) =  | 
|     92   viewer.canvas.setRGB(x, y, color.getRGB()) |     94   viewer.canvas.setRGB(x, y, color.getRGB()) | 
|     93  |     95  | 
|     94  |     96  | 
|     95 // calculates the number of iterations using lazy lists (streams) |     97 // calculates the number of iterations using lazy lists  | 
|         |     98 // (streams) | 
|     96 //   the iteration goes on for a maximum of max steps, |     99 //   the iteration goes on for a maximum of max steps, | 
|     97 //   but might leave early when the pred is satisfied |    100 //   but might leave early when the pred is satisfied | 
|     98 def iterations(c: Complex, max: Int) : Int = { |    101 def iterations(c: Complex, max: Int) : Int = { | 
|     99   def next(z: Complex) = z * z + c     |    102   def next(z: Complex) = z * z + c     | 
|    100   def pred(z: Complex) = z.abs() < 2    // exit condition |    103   def pred(z: Complex) = z.abs() < 2    // exit condition | 
|    163  |    166  | 
|    164 // some more computations with example 3 |    167 // some more computations with example 3 | 
|    165  |    168  | 
|    166 val delta = (exc2 - exc1) * 0.0333 |    169 val delta = (exc2 - exc1) * 0.0333 | 
|    167  |    170  | 
|    168 //println(s"${time_needed( |    171 println(s"${time_needed( | 
|    169 //  for (n <- (0 to 12))  |    172   for (n <- (0 to 12))  | 
|    170 //     mandelbrot(exc1 + delta * n,  |    173      mandelbrot(exc1 + delta * n,  | 
|    171 //                exc2 - delta * n, 100))} secs")  |    174                 exc2 - delta * n, 100))} secs")  | 
|    172  |    175  | 
|    173  |    176  | 
|    174  |    177  | 
|    175 // Larry Paulson's example |    178 // Larry Paulson's example | 
|    176 val exl1 = -0.74364990 + 0.13188170 * i |    179 val exl1 = -0.74364990 + 0.13188170 * i |