Search Apps Documentation Source Content File Folder Download Copy Actions Download State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

example_test.gno

1.78 Kb · 67 lines
 1package art
 2
 3// heart is an 8x6 indexed sprite: 0 background, 1 body, 2 highlight.
 4var (
 5	heartPal = Palette{"", "#d64550", "#f7a8b0"}
 6	heartIdx = []uint8{
 7		0, 1, 1, 0, 0, 1, 1, 0,
 8		1, 1, 1, 2, 2, 1, 1, 1,
 9		1, 1, 1, 1, 1, 1, 1, 1,
10		0, 1, 1, 1, 1, 1, 1, 0,
11		0, 0, 1, 1, 1, 1, 0, 0,
12		0, 0, 0, 1, 1, 0, 0, 0,
13	}
14)
15
16func heart() *Pix {
17	return &Pix{W: 8, H: 6, Idx: heartIdx, Pal: heartPal}
18}
19
20// One glyph per palette index, each pixel two cells wide so the sprite keeps
21// its proportions in a terminal. This is the default for indexed art.
22func ExamplePix_Canvas_glyphs() {
23	println(heart().Canvas(Glyphs).Text())
24	// Output:
25	//   ####    ####
26	// ######@@@@######
27	// ################
28	//   ############
29	//     ########
30	//       ####
31}
32
33// The same sprite at four times the density, in Braille. Monochrome by
34// construction: a Braille cell has eight dots and no colours, so a pixel is
35// only on or off.
36func ExamplePix_Canvas_braille() {
37	println(heart().Canvas(Braille).Text())
38	// Output:
39	// ⢾⣷⣾⡷
40	// ⠀⠙⠋⠀
41}
42
43// Quadrants pack 2x2 into one cell. Asked for no colour, the mode has nothing
44// left to say with two colours and degrades to a density map, which is still
45// the densest thing a plain-text consumer can be handed.
46func ExamplePix_Canvas_quadrant() {
47	println(heart().CanvasOpts(Opts{Mode: Quadrant}).Text())
48	// Output:
49	// ▟▙▟▙
50	// ▜██▛
51	//  ▜▛
52}
53
54// Drawing on a Canvas directly, with a border around it.
55func ExampleCanvas_Frame() {
56	c := NewCanvas(11, 3)
57	c.Write(0, 0, "gno.land")
58	c.HLine(0, 1, 11, '─')
59	c.Write(0, 2, "ascii art")
60	println(c.Frame("art", Round).Text())
61	// Output:
62	// ╭─art───────╮
63	// │gno.land   │
64	// │───────────│
65	// │ascii art  │
66	// ╰───────────╯
67}