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

2
fs.go
View File

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

View File

@ -5,6 +5,7 @@ import (
_ "image/png" _ "image/png"
"io/ioutil" "io/ioutil"
"log" "log"
"math/rand"
) )
func main() { 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 // pool of workers unionizing, ready to blend a new picture using the power of friendship
var pool blendWorkerPool var pool blendWorkerPool