-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
57 lines (46 loc) · 1.09 KB
/
main.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
package main
import (
"flag"
"image/png"
"log"
"os"
"runtime"
"strconv"
"strings"
"time"
"./mandelbrot"
)
var (
size = flag.String("size", "640x480", "size of the output image")
tasks = flag.Int("tasks", 2, "max number of parallel processes")
output = flag.String("out", "zad16.png", "name of the output image file")
)
func init() {
flag.StringVar(size, "s", "640x480", "size of the output image")
flag.IntVar(tasks, "t", 1, "max number of parallel processes")
flag.StringVar(output, "o", "zad16.png", "name of the output image file")
}
func main() {
start := time.Now()
// read the command lines params
flag.Parse()
runtime.GOMAXPROCS(*tasks)
sizes := strings.Split(*size, "x")
width, _ := strconv.Atoi(sizes[0])
height, _ := strconv.Atoi(sizes[1])
// open a new file
f, err := os.Create(*output)
if err != nil {
log.Fatal(err)
}
// create the image
img := mandelbrot.Create(width, height, *tasks)
// and encoding it
err = png.Encode(f, img)
// unless you can't
if err != nil {
log.Fatal(err)
}
elapsed := time.Since(start)
log.Printf("Execution took %s", elapsed)
}