Example #1
0
File: main.go Project: otiai10/gat
func getCanvas(col, row int, img image.Image) gat.Rect {
	switch {
	case col > 0:
		return gat.Rect{
			Col: uint16(col), // restrict output canvas by given "col"
			Row: uint16(float64(col) * (float64(img.Bounds().Max.Y) / float64(img.Bounds().Max.X))),
		}
	case row > 0:
		return gat.Rect{
			Row: uint16(row), // restrict output canvas by given "row"
			Col: uint16(float64(row) * (float64(img.Bounds().Max.X) / float64(img.Bounds().Max.Y))),
		}
	default:
		canvas, terminal := gat.Rect{}, gat.GetTerminal()
		rAvailable, rSource := float64(terminal.Col)/float64(terminal.Row)/float64(len(gat.Cell)), float64(img.Bounds().Size().X)/float64(img.Bounds().Size().Y)
		if rAvailable > rSource { // source image is vertically bigger than available canvas
			canvas.Row = terminal.Row // restrict output canvas by current terminal's row
			canvas.Col = uint16(float64(terminal.Row) * rSource / float64(len(gat.Cell)))
		} else { // source image is horizontally bigger than available canvas
			canvas.Col = terminal.Col // restrict output canvas by current terminal's col
			canvas.Row = uint16(float64(terminal.Col) / rSource / float64(len(gat.Cell)))
		}
		return canvas
	}
}
Example #2
0
func main() {

	if daemon {
		startDaemon()
		return
	}

	entry := amesh.GetEntry()

	meshLayer, err := getImage(entry.Mesh)
	onerror(err)

	base := image.NewRGBA(meshLayer.Bounds())

	if geo {
		geoLayer, err := getImage(entry.Map)
		onerror(err)
		draw.Draw(base, base.Bounds(), geoLayer, image.Point{0, 0}, 0)
	}

	draw.Draw(base, meshLayer.Bounds(), meshLayer, image.Point{0, 0}, 0)

	if mesh {
		mapLayer, err := getImage(entry.Mask)
		onerror(err)
		draw.Draw(base, base.Bounds(), mapLayer, image.Point{0, 0}, 0)
	}

	gat.NewClient(gat.GetTerminal()).Set(gat.SimpleBorder{}).PrintImage(base)
	fmt.Println("#amesh", entry.URL)
}