From 512efe4aaa4306ef268e15719c1e977088110d85 Mon Sep 17 00:00:00 2001 From: peperoncino <2wua4nlyi@gmail.com> Date: Sun, 3 Apr 2022 04:08:57 +0900 Subject: [PATCH] made sesame optional --- main.go | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/main.go b/main.go index e192ada..6aaf29e 100644 --- a/main.go +++ b/main.go @@ -12,7 +12,6 @@ import ( "image/png" "io/ioutil" "log" - "math/rand" "net/http" "os" "strings" @@ -55,6 +54,7 @@ func saveImage(filename string, img image.Image) error { var toppings [6]Topping var top Topping +var topWithSesame Topping var bottom Topping func init() { @@ -63,12 +63,12 @@ func init() { log.Fatal(err) } - if randBool() { - top.Img, err = loadImage(fs, "/top.png") - } else { - top.Img, err = loadImage(fs, "/top-sesame.png") + top.Img, err = loadImage(fs, "/top.png") + if err != nil { + log.Fatal(err) } + topWithSesame.Img, err = loadImage(fs, "/top-sesame.png") if err != nil { log.Fatal(err) } @@ -114,16 +114,22 @@ func main() { var nBurger int var rInterval float64 var fileName string + var sesame bool flag.IntVar(&nBurger, "n", 1, "number of big burger") flag.Float64Var(&rInterval, "i", 1.0, "rate of intervals") flag.StringVar(&fileName, "o", "", "output image file") + flag.BoolVar(&sesame, "s", false,"buns with sesame") for i := 0; i < len(toppings); i++ { flag.IntVar(&toppings[i].Count, toppings[i].Option, toppings[i].Count, fmt.Sprintf("how many %s", toppings[i].Name)) } flag.Parse() + if sesame{ + top = topWithSesame + } + // Count number of unique toppings uniqueToppingCount := 0 for i := 0; i < len(toppings); i++ { @@ -227,8 +233,3 @@ func getDA2() string { } return string(b[:n]) } - -func randBool() bool { - rand.Seed(time.Now().UnixNano()) - return rand.Intn(2) == 1 -}