Skip to content

Commit 8ddb4a8

Browse files
committed
Rename variable for number in complex plane from z0 to c
1 parent 8227a20 commit 8ddb4a8

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ go build
5656

5757
## About the Algorithm
5858
### The Math in a Nutshell
59-
The Mandelbrot set is defined as the set of complex numbers $z_0$ for which the series
59+
The Mandelbrot set is defined as the set of complex numbers $c$ for which the series
6060

61-
$$z_{n+1} = z²_n + z_0$$
61+
$$z_{n+1} = z²_n + c$$
6262

63-
is bounded for all $n ≥ 0$. In other words, $z_0$ is part of the Mandelbrot set if $z_n$ does not approach infinity. This is equivalent to the magnitude $|z_n| ≤ 2$ for all $n ≥ 0$.
63+
is bounded for all $n ≥ 0$. In other words, $c$ is part of the Mandelbrot set if $z_n$ does not approach infinity. This is equivalent to the magnitude $|z_n| ≤ 2$ for all $n ≥ 0$.
6464

6565
### But how is this visualized in a colorful image?
66-
The image is interpreted as complex plane, i.e. the horizontal axis being the real part and the vertical axis representing the complex part of $z_0$.
66+
The image is interpreted as complex plane, i.e. the horizontal axis being the real part and the vertical axis representing the complex part of $c$.
6767

6868
The colors are determined by the so-called **naïve escape time algorithm**. It's as simple as that: A pixel is painted in a predefined color (often black) if it's in the set and will have another color if it's not. The color is determined by the number of iterations $n$ needed for $z_n$ to exceed $|z_n| = 2$. This $n$ is the escape time, and $|z_n| ≥ 2$ is the escape condition. In our implementation, this is done via the _hue_ parameter in the [HSL color model](https://en.wikipedia.org/wiki/HSL_and_HSV) for non-grayscale images, and the _lightness_ parameter for grayscale images.
6969

benchmark_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,15 +112,15 @@ func BenchmarkGetColorFromMandelbrotUnlimited(b *testing.B) {
112112
func BenchmarkRunMandelbrot(b *testing.B) {
113113
benchmarkConfig := getBenchmarkConfig()
114114

115-
z0 := complex(-0.5, 0) // (-0.5, 0) is part of the mandelbrot set, i.e. zn is bounded for all zn
115+
c := complex(-0.5, 0) // (-0.5, 0) is part of the mandelbrot set, i.e. zn is bounded for all zn
116116
for _, maxIter := range benchmarkConfig.MaxIterValues {
117117
testId := fmt.Sprintf("MaxIter_%d", maxIter)
118118
b.Run(testId, func(subB *testing.B) {
119119
imgConf.MaxIter = maxIter
120120
subB.ResetTimer()
121121

122122
for i := 0; i < subB.N; i++ {
123-
runMandelbrot(z0)
123+
runMandelbrot(c)
124124
}
125125
})
126126
}

mandelbrot.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66
"math/cmplx"
77
)
88

9-
func getColorForComplexNr(z0 complex128) color.RGBA {
10-
return getColorFromMandelbrot(runMandelbrot(z0))
9+
func getColorForComplexNr(c complex128) color.RGBA {
10+
return getColorFromMandelbrot(runMandelbrot(c))
1111
}
1212

1313
func getColorFromMandelbrot(isUnlimited bool, magnitude float64, iterations int) color.RGBA {
@@ -27,15 +27,15 @@ func getColorFromMandelbrot(isUnlimited bool, magnitude float64, iterations int)
2727
}
2828
}
2929

30-
func runMandelbrot(z0 complex128) (bool, float64, int) {
30+
func runMandelbrot(c complex128) (bool, float64, int) {
3131
var z complex128
3232

3333
for i := 0; i < imgConf.MaxIter; i++ {
3434
magnitude := cmplx.Abs(z)
3535
if magnitude > 2 {
3636
return true, magnitude, i
3737
}
38-
z = z*z + z0
38+
z = z*z + c
3939
}
4040
return false, 0, 0
4141
}

0 commit comments

Comments
 (0)