progs/mandelbrot.scala
changeset 166 780c40aaad27
parent 143 11396c17cd8b
child 167 349d706586ef
equal deleted inserted replaced
165:1347bbd86c52 166:780c40aaad27
    73   viewer.clearCanvas(black)
    73   viewer.clearCanvas(black)
    74    
    74    
    75   val delta_x = (end.a - start.a) / W
    75   val delta_x = (end.a - start.a) / W
    76   val delta_y = (end.b - start.b) / H
    76   val delta_y = (end.b - start.b) / H
    77    
    77    
    78   for (y0 <- (0 until H)) {
    78   for (y0 <- (0 until H).par) {
    79     for (x0 <- (0 until W)) {
    79     for (x0 <- (0 until W).par) {
    80     
    80     
    81      val c = start + Complex(x0 * delta_x, y0 * delta_y)
    81      val c = start + Complex(x0 * delta_x, y0 * delta_y)
    82 
    82 
    83      def iters(z: Complex, it: Int) : Color = {
    83      def iters(z: Complex, it: Int) : Color = {
    84        if (it < level && z.abs < 2) iters(z * z + c, it + 1) else 
    84        if (it < level && z.abs < 2) iters(z * z + c, it + 1) else 
   111 
   111 
   112 // example 2
   112 // example 2
   113 val exb1 = Complex(-0.37465401, 0.659227668)
   113 val exb1 = Complex(-0.37465401, 0.659227668)
   114 val exb2 = Complex(-0.37332410, 0.66020767)
   114 val exb2 = Complex(-0.37332410, 0.66020767)
   115 
   115 
   116 time_needed(mandelbrot(exb1, exb2, 1000))
   116 //time_needed(mandelbrot(exb1, exb2, 1000))
   117 
   117 
   118 // example 3
   118 // example 3
   119 val exc1 = Complex(0.435396403, 0.367981352)
   119 val exc1 = Complex(0.435396403, 0.367981352)
   120 val exc2 = Complex(0.451687191, 0.380210061)
   120 val exc2 = Complex(0.451687191, 0.380210061)
   121 
   121 
   122 time_needed(mandelbrot(exc1, exc2, 1000))
   122 //time_needed(mandelbrot(exc1, exc2, 1000))
   123 
   123 
   124 // some more computations with example 3
   124 // some more computations with example 3
   125 val delta = (exc2 - exc1) * 0.0333
   125 val delta = (exc2 - exc1) * 0.0333
   126 
   126 
   127 time_needed(
   127 //time_needed(
   128   for (i <- (0 to 12)) 
   128 //  for (i <- (0 to 12)) 
   129      mandelbrot(exc1 + delta * i, 
   129 //     mandelbrot(exc1 + delta * i, 
   130                 exc2 - delta * i, 1000))
   130 //                exc2 - delta * i, 1000))
   131 
   131 
   132 
   132 
   133 
   133