seed can be specified to reproduce output

This commit is contained in:
Ali Gator 2022-05-02 20:29:22 +02:00
parent 8d582df5ee
commit 5cb5e3bf9b
3 changed files with 12 additions and 2 deletions

View File

@ -7,6 +7,7 @@ import (
"os"
"strconv"
"strings"
"time"
)
type Config struct {
@ -21,6 +22,7 @@ type Config struct {
Sepia bool
Amount int
Quiet bool
Seed int64
}
// loads configuration values from json file
@ -47,6 +49,9 @@ func (c *Config) SetOutputDimensions() {
}
func initConfigRegister() {
// default seed for the RNG
seed := time.Now().UnixNano()
// command line arguments
flag.StringVar(&ConfigRegister.Method, "blending", "darken", "Blending methods : darken, lighten, average, fuckyfun")
flag.StringVar(&ConfigRegister.OutputDir, "output", "./", "Output directory")
@ -56,7 +61,9 @@ func initConfigRegister() {
flag.BoolVar(&ConfigRegister.Grayscale, "grayscale", false, "Output image in shade of gray (around 50)")
flag.BoolVar(&ConfigRegister.Sepia, "sepia", false, "Output image with sepia tone")
flag.IntVar(&ConfigRegister.Amount, "amount", 2, "Number of images to blend together")
flag.Int64Var(&ConfigRegister.Seed, "seed", seed, "Number of images to blend together")
flag.BoolVar(&ConfigRegister.Quiet, "quiet", false, "No progress messages")
flag.Parse()
// set output's width and height

2
fs.go
View File

@ -7,7 +7,6 @@ import (
"os"
"path/filepath"
"strings"
"time"
)
// load an image from a file into an Image value
@ -52,7 +51,6 @@ func getImagesList(path string) []string {
// Randomly choose x number of image from a given folder
func getRandomImage() string {
rand.Seed(time.Now().UnixNano())
dir := getImagesList(ConfigRegister.InputDir)
index := rand.Intn(len(dir))
return dir[index]

View File

@ -5,6 +5,7 @@ import (
_ "image/png"
"io/ioutil"
"log"
"math/rand"
)
func main() {
@ -16,6 +17,10 @@ func main() {
}
// init RNG
rand.Seed(ConfigRegister.Seed)
log.Println("Seed :", ConfigRegister.Seed)
// pool of workers unionizing, ready to blend a new picture using the power of friendship
var pool blendWorkerPool