mandelbrot.jl 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. #
  5. # StarPU is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU Lesser General Public License as published by
  7. # the Free Software Foundation; either version 2.1 of the License, or (at
  8. # your option) any later version.
  9. #
  10. # StarPU is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. #
  16. function mandelbrotjl(pixels ::Matrix{Int64}, centerr ::Float64, centeri ::Float64)
  17. height,width = size(pixels)
  18. zoom = width * 0.25296875
  19. val_diverge = 2.0
  20. max_iterations = (width/2) * 0.049715909 * log10(zoom);
  21. for y = 1:height
  22. for x = 1:width
  23. cr = centerr + (x - (width / 2))/zoom
  24. zr = cr
  25. ci = centeri + (y - (height / 2))/zoom
  26. zi = ci
  27. n = 0
  28. while ((n < max_iterations) && (zr*zr + zi*zi < val_diverge*val_diverge))
  29. tmp = zr*zr - zi*zi + cr
  30. zi = 2*zr*zi + ci
  31. zr = tmp
  32. n = n+1
  33. end
  34. if (n < max_iterations)
  35. pixels[y,x] = round(255 * n / max_iterations)
  36. else
  37. pixels[y,x] = 0
  38. end
  39. end
  40. end
  41. end