Playing around with images and drawing
mostly in preparation for doing image stuff in the Conway's Game of Life implementation.
This commit is contained in:
parent
3e013ce1a5
commit
8b536de45c
@ -15,7 +15,8 @@ TARGETS = \
|
|||||||
github.com/meatballhat/box-o-sand/gotime/gotour-artifacts/ranges \
|
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/gotour-artifacts/selects \
|
||||||
github.com/meatballhat/box-o-sand/gotime/junkdrawer/greppish \
|
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
|
test: build
|
||||||
|
52
gotime/junkdrawer/randimg/main.go
Normal file
52
gotime/junkdrawer/randimg/main.go
Normal file
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user