-
Notifications
You must be signed in to change notification settings - Fork 1
/
3.5.go
43 lines (36 loc) · 770 Bytes
/
3.5.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
package main
import (
"image"
"image/color"
"image/png"
"math/cmplx"
"os"
)
func main() {
const (
xmin, ymin, xmax, ymax = -2, -2, +2, +2
width, height = 1024, 1024
)
img := image.NewRGBA(image.Rect(0, 0, width, height))
for py := 0; py < height; py++ {
y := float64(py)/height*(ymax-ymin) + ymin
for px := 0; px < width; px++ {
x := float64(px)/height*(xmax-xmin) + xmin
z := complex(x, y)
img.Set(px, py, mandelbort(z))
}
}
png.Encode(os.Stdout, img)
}
func mandelbort(z complex128) color.Color {
const iterations = 200
const contrast = 15
var v complex128
for n := uint8(0); n < iterations; n++ {
v = v*v + z
if cmplx.Abs(v) > 2 {
return color.RGBA{R: 100, G: 20, B: 30, A: 255-contrast*n}
}
}
return color.Black
}