Esempio n. 1
0
func genStarfield(pl, pc int) *gc.Pad {
	pad, err := gc.NewPad(pl, pc)
	if err != nil {
		log.Fatal(err)
	}
	stars := int(float64(pc*pl) * density)
	planets := int(float64(pc*pl) * planet_density)
	for i := 0; i < stars; i++ {
		y, x := rand.Intn(pl), rand.Intn(pc)
		c := int16(rand.Intn(4) + 1)
		pad.AttrOn(gc.A_BOLD | gc.ColorPair(c))
		pad.MovePrint(y, x, ".")
		pad.AttrOff(gc.A_BOLD | gc.ColorPair(c))
	}
	for i := 0; i < planets; i++ {
		y, x := rand.Intn(pl), rand.Intn(pc)
		c := int16(rand.Intn(2) + 5)
		pad.ColorOn(c)
		if i%2 == 0 {
			pad.MoveAddChar(y, x, 'O')
		}
		pad.MoveAddChar(y, x, 'o')
		pad.ColorOff(c)
	}
	return pad
}
Esempio n. 2
0
func main() {
	_, err := gc.Init()
	if err != nil {
		log.Fatal(err)
	}
	defer gc.End()

	// create a new pad of 50 rows and 200 columns...
	var pad *gc.Pad
	pad, err = gc.NewPad(50, 200)
	if err != nil {
		log.Fatal(err)
	}
	// ...and fill it with some characters
	for x := 0; x < 50; x++ {
		pad.MovePrint(x, x, "This is a pad.")
	}
	// Refresh the pad to show only a portion of the pad. Understanding
	// what these coordinates mean can be a bit tricky. The first two
	// coordinates are the position in the pad, in this case 0,5 (remember
	// the coordinates in ncurses are y,x). The second set of numbers are the
	// coordinates on the screen on which to display the content, so row 5,
	// column 10. The last set of numbers tell how high and how wide the
	// rectangle to displayed should be, in this case 15 rows long and 25
	// columns wide.
	pad.Refresh(0, 5, 5, 10, 15, 25)
	pad.GetChar()
}