# Sin(z) fractals

##### November 6, 2022

Another interesting set of fractals is produced by looking at the Julia set of the iterated function

$$ z_{n+1} = \sin (z_n) \cdot c. $$

Instead of looking at the magnitude of the complex number to determine if the orbit escapes to infinity, only the imaginary part of $z$ is used in this case. If the imaginary part of $z$ is greater than 50, then it is decided that the orbit escapes to infinity. This is important to get the correct result, because it won’t work if the escape criteria of a Mandelbrot set are used.

## Complex function sin(z) #

The sine function of a complex number $z$ is defined with the relationship

$$ \sin(z) = \sin(a + bi) = \sin a \cdot \cosh b + (\cos a \cdot \sinh b)i, $$

which is used to define the `complex_sin`

function.

```
1fn complex_sin(z: Complex) -> Complex {
2 Complex {
3 a: z.a.sin() * z.b.cosh(),
4 b: z.a.cos() * z.b.sinh()
5 }
6}
```

## Iterated map of sin(z) #

With that out of the way, a `csinz`

function is defined that will generate the fractal.
Note that the smooth iteration counter is not used here because it is for exponential functions, which is not the case here.

```
1fn csinz(x: f32, y: f32) -> f32 {
2 let mut z = Complex { a: x, b: y };
3 let c = Complex { a: 1.0, b: 0.0 };
4 let max = 256;
5 let mut i = 0;
6 while i < max && z.b.abs() < 50.0 {
7 z = c * complex_sin(z);
8 i += 1;
9 }
10 return i as f32 / max as f32;
11}
```

Because this is a Julia set, we pick the point $1 + 0i$ as a start. The fractal is colored with the function that is defined in the Mandelbrot with Rust post.

And voila, there it is.

## Renders of sin(z) #

If we use different values for $c$, we will get different Julia sets. There are quite a few awesome looking sets that we can find. The rest of this post shows renderings of different Julia sets.

The colorization is done with the cosine color function that is defined in the Mandelbrot with Rust post. Note that we are using a few different color palettes here, which can be found on Inigo Quilez’s page about this colorization technique.

## Shadertoy implementation #

I have also implemented the fractal as a shader on Shadertoy. It is included below. You can use the mouse to view the different Julia sets.