Added tileblueprint.

- Utility that generates a PNG with tiles.
This commit is contained in:
Sander Schobers 2019-12-24 12:55:02 +01:00
parent 0cd5cb4ad1
commit 319dc52496

View File

@ -0,0 +1,64 @@
package main
import (
"errors"
"flag"
"image"
"image/color"
"log"
"github.com/llgcode/draw2d/draw2dkit"
"github.com/llgcode/draw2d/draw2dimg"
)
func main() {
err := run()
if err != nil {
log.Fatal(err)
}
}
func run() error {
var dpi int
flag.IntVar(&dpi, "dpi", 300, "dpi")
flag.Parse()
path := flag.Arg(0)
if path == "" {
return errors.New("no output path specified")
}
bounds := image.Rect(0, 0, dpi*827/100, dpi*1169/100)
scale := float64(dpi) / 100
margin := 5. * scale
tileWidth, tileHeight := 140.*scale, 200.*scale
tileOffsetWidth, tileOffsetHeight := tileWidth+4.*margin, tileHeight+4.*margin
im := image.NewRGBA(bounds)
gc := draw2dimg.NewGraphicContext(im)
marginColor := color.Gray{Y: 63}
tileColor := color.Gray{Y: 127}
gc.SetLineWidth(1)
for y := 0.; y < float64(bounds.Max.Y)-tileOffsetHeight; y += tileOffsetHeight {
for x := 0.; x < float64(bounds.Max.X)-tileOffsetWidth; x += tileOffsetWidth {
draw2dkit.Rectangle(gc, x+margin-1, y+margin-1, x+tileOffsetWidth-margin, y+tileOffsetHeight-margin)
gc.SetStrokeColor(marginColor)
gc.Stroke()
tileX, tileY := x+2*margin-.5, y+2*margin-.5
gc.MoveTo(tileX, tileY+.25*tileHeight)
gc.LineTo(tileX, tileY+.75*tileHeight)
gc.LineTo(tileX+.5*tileWidth, tileY+tileHeight)
gc.LineTo(tileX+tileWidth, tileY+.75*tileHeight)
gc.LineTo(tileX+tileWidth, tileY+.25*tileHeight)
gc.LineTo(tileX+.5*tileWidth, tileY+.5*tileHeight)
gc.LineTo(tileX, tileY+.25*tileHeight)
gc.LineTo(tileX+.5*tileWidth, tileY)
gc.LineTo(tileX+tileWidth, tileY+.25*tileHeight)
gc.MoveTo(tileX+.5*tileWidth, tileY+.5*tileHeight)
gc.LineTo(tileX+.5*tileWidth, tileY+tileHeight)
gc.SetStrokeColor(tileColor)
gc.Stroke()
}
}
return draw2dimg.SaveToPngFile(path, im)
}