-
Notifications
You must be signed in to change notification settings - Fork 1
/
pix.go
43 lines (36 loc) · 916 Bytes
/
pix.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 pix
import (
"image/png"
)
type Options struct {
Width, Height int
RandomSeed int64
Sort SortOptions
Seeds []int
Output string
CompressionLevel png.CompressionLevel
}
func Place(colors []SampledColor, opts Options) error {
// Create a canvas object
canvas := NewCanvas(opts.Width, opts.Height, opts.RandomSeed)
// Place an initial seed color in the middle of the canvas
seeds := opts.Seeds
if seeds == nil {
seeds = []int{opts.Width / 2, opts.Height / 2}
}
rest, err := canvas.PlaceSeeds(colors, seeds...)
if err != nil {
return err
}
// Place the rest of the colors using the growth algorithm
for _, color := range rest {
canvas.Place(color)
}
// Save the output image
outPath := opts.Output
if outPath == "" {
outPath = "out.png"
}
// fmt.Println("saving", outPath)
return canvas.SaveImage(outPath, opts.CompressionLevel)
}