/
main.go
73 lines (56 loc) · 1.55 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package main
import (
"flag"
"log"
"math/rand"
"os"
"time"
"github.com/armhold/polygen"
)
var (
maxGen int
polyCount int
srcImgFile string
dstImgFile string
cpArg string
host, port string
)
func init() {
flag.IntVar(&maxGen, "max", 100000, "the number of generations")
flag.IntVar(&polyCount, "poly", 50, "the number of polygons")
flag.StringVar(&srcImgFile, "source", "images/mona_lisa.jpg", "the source input image file")
flag.StringVar(&dstImgFile, "dest", "output.png", "the output image file")
flag.StringVar(&cpArg, "cp", "", "checkpoint file")
flag.StringVar(&host, "host", "localhost", "which hostname to http listen on")
flag.StringVar(&port, "port", "8080", "which port to http listen on")
flag.Parse()
if srcImgFile == "" || dstImgFile == "" {
flag.Usage()
os.Exit(1)
}
if port == "" {
port = "8080"
}
if host == "" {
host = "localhost"
}
rand.Seed(time.Now().UTC().UnixNano())
}
func main() {
refImg := polygen.MustReadImage(srcImgFile)
// a set of thread-safe images that can be updated by the evolver, and displayed via the web
var previews []*polygen.SafeImage
totalImages := polygen.PopulationCount
placeholder := refImg.Bounds()
for i := 0; i < totalImages; i++ {
img := polygen.NewSafeImage(placeholder)
previews = append(previews, img)
}
go polygen.Serve(host+":"+port, refImg, previews)
cp := polygen.DeriveCheckpointFile(srcImgFile, cpArg, polyCount)
evolver, err := polygen.NewEvolver(refImg, dstImgFile, cp)
if err != nil {
log.Fatal(err)
}
evolver.Run(maxGen, polyCount, previews)
}