-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfunctions.go
50 lines (41 loc) · 948 Bytes
/
functions.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import "math"
func mandelbrot(cr float64, ci float64, maxIterations int, bailout float64) int {
var zr float64
var zi float64
iterations := 0
var temp float64
for zr*zr+zi*zi < bailout && iterations < maxIterations {
temp = zr*zr - zi*zi + cr
zi = 2.0*zr*zi + ci
zr = temp
iterations++
}
return iterations
}
func julia(cr float64, ci float64, maxIterations int, bailout float64) int {
iterations := 0
var temp float64
for cr*cr+ci*ci < bailout && iterations < maxIterations {
temp = cr*cr - ci*ci - 0.7
ci = 2.0*cr*ci + 0.27015
cr = temp
iterations++
}
return iterations
}
func burningShip(cr float64, ci float64, maxIterations int, bailout float64) int {
var (
zr float64
zi float64
temp float64
)
iterations := 0
for zr*zr+zi*zi < bailout && iterations < maxIterations {
temp = zr*zr - zi*zi + cr
zi = math.Abs(2.0*zr*zi) + ci
zr = temp
iterations++
}
return iterations
}