How to resolve the algorithm Mandelbrot set step by step in the Elixir programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm Mandelbrot set step by step in the Elixir programming language
Table of Contents
Problem Statement
Generate and draw the Mandelbrot set.
Note that there are many algorithms to draw Mandelbrot set and there are many functions which generate it .
Let's start with the solution:
Step by Step solution about How to resolve the algorithm Mandelbrot set step by step in the Elixir programming language
Source code in the elixir programming language
defmodule Mandelbrot do
def set do
xsize = 59
ysize = 21
minIm = -1.0
maxIm = 1.0
minRe = -2.0
maxRe = 1.0
stepX = (maxRe - minRe) / xsize
stepY = (maxIm - minIm) / ysize
Enum.each(0..ysize, fn y ->
im = minIm + stepY * y
Enum.map(0..xsize, fn x ->
re = minRe + stepX * x
62 - loop(0, re, im, re, im, re*re+im*im)
end) |> IO.puts
end)
end
defp loop(n, _, _, _, _, _) when n>=30, do: n
defp loop(n, _, _, _, _, v) when v>4.0, do: n-1
defp loop(n, re, im, zr, zi, _) do
a = zr * zr
b = zi * zi
loop(n+1, re, im, a-b+re, 2*zr*zi+im, a+b)
end
end
Mandelbrot.set
You may also check:How to resolve the algorithm Guess the number/With feedback (player) step by step in the Elixir programming language
You may also check:How to resolve the algorithm Copy stdin to stdout step by step in the Prolog programming language
You may also check:How to resolve the algorithm Sum of squares step by step in the VBA programming language
You may also check:How to resolve the algorithm Empty program step by step in the EasyLang programming language
You may also check:How to resolve the algorithm Terminal control/Inverse video step by step in the 6502 Assembly programming language