diff --git a/gotime/Makefile b/gotime/Makefile index 55d3647..07187ae 100644 --- a/gotime/Makefile +++ b/gotime/Makefile @@ -15,7 +15,8 @@ TARGETS = \ github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/ranges \ github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/selects \ github.com/meatballhat/box-o-sand/gotime/junkdrawer/greppish \ - github.com/meatballhat/box-o-sand/gotime/junkdrawer/reflectish + github.com/meatballhat/box-o-sand/gotime/junkdrawer/reflectish \ + github.com/meatballhat/box-o-sand/gotime/junkdrawer/randimg test: build diff --git a/gotime/junkdrawer/randimg/main.go b/gotime/junkdrawer/randimg/main.go new file mode 100644 index 0000000..60432bb --- /dev/null +++ b/gotime/junkdrawer/randimg/main.go @@ -0,0 +1,52 @@ +package main + +import ( + "fmt" + "flag" + "image" + "image/color" + "image/draw" + "image/png" + "math/rand" + "os" + "time" +) + +var ( + outfile = flag.String("o", "randimg.png", "Output PNG file name") +) + +func main() { + flag.Parse() + rand.Seed(time.Now().UTC().UnixNano()) + + out, err := os.Create(*outfile) + if err != nil { + fmt.Fprintf(os.Stderr, "ERROR: %v\n", err) + os.Exit(1) + } + + imgRect := image.Rect(0, 0, 200, 200) + img := image.NewGray(imgRect) + draw.Draw(img, img.Bounds(), &image.Uniform{color.White}, image.ZP, draw.Src) + + for y := 0; y < 200; y += 10 { + for x := 0; x < 200; x += 10 { + fill := &image.Uniform{color.Black} + if rand.Intn(10) % 2 == 0 { + fill = &image.Uniform{color.White} + } + + draw.Draw(img, image.Rect(x, y, x+10, y+10), fill, image.ZP, draw.Src) + } + } + + err = png.Encode(out, img) + if err != nil { + fmt.Fprintf(os.Stderr, "ERROR: %v\n", err) + os.Exit(2) + } + + fmt.Printf("Wrote random image to \"%s\"\n", *outfile) + os.Exit(0) +}