I came across this picture the other day: (Credit to Josep M Batlle I Ferrer)
Your job is to generate this picture. This graph is generated by repeatedly applying newton's method to the graph of:
$$f(x)=\cosh(x)-1$$
In other words, repeatedly apply the following function to every point till the rectangular distance is less than some limit to a attractor:
$$g(x)=\frac{x \cdot \sinh(x) - \cosh(x) + 1}{\sinh(x)}$$
The process is described in psuedocode below:
let n be the maximum number of iterations
for every point (as a complex number) in the image:
repeat n times:
point = (point * sinh(point) - cosh(point) + 1) / sinh(point)
if the rectangular distance between the point and any attractor is less than 0.01:
break
end if
end repeat
color the point in the image depending on the nearest attractor and the number of iterations required
The rectangular distance is defined as max(abs(dx), abs(dy))
. We use rectangular distance instead of straight line distance so we get the wave shapes that make this graph so beautiful.
There is a attractor at 0+n*2i*PI
for any integer N. Thus at even increments of 2 PI in the imaginary direction.
Rules
- Your graph must include the area from
[-0.75, -0.75 + PI]
to[0.75, +0.75 + PI]
. - Resolution over this needs to be at least 256 by 256. Either characters or pixels. If you decide to cover a larger area you need to increase the resolution in proportion.
- Use at least 20 iterations.
- Both adjacent iteration counts and adjacent attractors need to be drawn in distinct colors. You must use at least 3 different colors. Coloring should soley be based on the attractor and iteration count.
- If any point causes a division by 0 or another math error, you may choose to render anything at this point. This is considered undefined behavior.
- Displaying a image, saving a image, or drawing ASCII art are all acceptable, as long as the other rules are met. If you draw ASCII art characters need to be ANSI colored.
- Please include a screenshot of the result in your answer
This is code golf, shortest answer wins. ASCII art answers do not compete against graphical answers in the same language.