grid2img

package module
v0.0.0-...-d15d1ac Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 18, 2018 License: MIT Imports: 9 Imported by: 0

README

grid2img

Converts a grid file (text-JSON) into an image. The grid file has a simple format and is meant to be edited by hand.

Grid File Syntax

A 2D array of integers defines the grid. The numbers in the array are keys to the Tiles list. Each tile can be a flat color or an image.

This grid file:

{
	"Cells":
	[
		[1,0,0],
		[0,2,0],
		[0,0,3],
		[0,0,0],
		[0,0,0],
		[6,0,0]
	],

	"Tiles":
	{
		"1":{"Color":{"R":200,"G":0,"B":0,"A":255}},
		"2":{"Color":{"R":200,"G":0,"B":200,"A":255}},
		"6":{"Color":{"R":0,"G":160,"B":0,"A":255}},
 		"3":{"Color":{"R":0,"G":0,"B":0,"A":255}, "Image":"test.jpg"}
	},

	"CellWidth":30,
	
	"GridLInes":
	{
		"Color":{"R":0,"G":0,"B":0,"A":150},
		"Width":1
	}
}

Will produce this output:

output

Usage

grid2img --grid [gridfile.json] --image [output.png]

If --grid is missing it will default to grid.json. If --image is missing it will default to img.png.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GridToImage

func GridToImage(g *Grid) *image.RGBA

func LoadTiles

func LoadTiles(g *Grid)

Types

type Cell

type Cell struct {
	Color color.RGBA
	Image string
	// contains filtered or unexported fields
}

func (Cell) Paint

func (a Cell) Paint(x, y, w int, img *image.RGBA)

Paint a sub region of img with the contents of this cell. Color fills the cell with that color Image fills the cell with the contents of Image (possibly scaled)

type Grid

type Grid struct {
	Cells     [][]int
	Tiles     map[int]Cell
	CellWidth int
	GridLines GridLine
}

func InitGrid

func InitGrid(x, y, cellWidth int) *Grid

type GridLine

type GridLine struct {
	Color color.RGBA
	Width int
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL