-
Notifications
You must be signed in to change notification settings - Fork 4
/
bbmandelbrot_test.go
executable file
·69 lines (60 loc) · 1.45 KB
/
bbmandelbrot_test.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package bbmandelbrot
import (
"flag"
"fmt"
"image/png"
"os"
"runtime"
"testing"
"time"
)
var (
cscheme string
fname string
width uint64
height uint64
cx1 uint64
cx2 uint64
cy1 uint64
cy2 uint64
csr int
csg int
csb int
)
func Test_Mandelbrot(t *testing.T) {
start := time.Now()
runtime.GOMAXPROCS(runtime.NumCPU())
flag.StringVar(&fname, "f", "mandelbrot.png", "destination filename")
flag.Uint64Var(&width, "w", 2560, "fractal width")
flag.Uint64Var(&height, "h", 2560, "fractal height")
flag.Uint64Var(&cx1, "cx1", 0, "crop width start")
flag.Uint64Var(&cx2, "cx2", 0, "crop width end")
flag.Uint64Var(&cy1, "cy1", 0, "crop height start")
flag.Uint64Var(&cy2, "cy2", 0, "crop height end")
flag.IntVar(&csr, "r", 2, "color scheme (red)")
flag.IntVar(&csg, "g", 3, "color scheme (green)")
flag.IntVar(&csb, "b", 1, "color scheme (blue)")
flag.Parse()
if cx2 == 0 {
cx2 = width
}
if cy2 == 0 {
cy2 = height
}
img, retstr := Mandelbrot(width, height, cx1, cx2, cy1, cy2, csr, csg, csb)
fmt.Println(retstr)
file, err := os.Create(fname)
defer file.Close()
if err != nil || file == nil {
file, err = os.Open(fname)
defer file.Close()
if err != nil {
t.Error(fmt.Sprintf("Error opening file: %s\n", err))
}
}
err = png.Encode(file, img)
if err != nil {
t.Error(fmt.Sprintf("Error encoding image: %s\n", err))
}
fmt.Printf("\033[2Jimage saved to %v after %v\n", fname, time.Since(start))
}