-
Notifications
You must be signed in to change notification settings - Fork 104
/
graphics_test.go
63 lines (49 loc) · 1.57 KB
/
graphics_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package chart_test
import (
"fmt"
"image/color"
"math"
"testing"
"github.com/vdobler/chart"
"github.com/vdobler/chart/txtg"
)
const r = 18
const ri = 10
func initDemoCircle() *txtg.TextGraphics {
g := txtg.New(60, 40)
g.Line(0, 20, 59, 20, chart.Style{Symbol: '-'})
g.Line(30, 0, 30, 39, chart.Style{Symbol: '|'})
for p := 0.0; p <= 2*math.Pi; p += 0.1 {
x := int(r * math.Cos(p) * 1.5)
y := int(r * math.Sin(p))
g.Symbol(30+x, 20+y, chart.Style{Symbol: '*'})
}
return g
}
func TestGenericWedge(t *testing.T) {
g := initDemoCircle()
red, blue := color.RGBA{0xff, 0, 0, 0}, color.RGBA{0, 0, 0xff, 0}
s := chart.Style{Symbol: '#', FillColor: red, LineColor: blue}
ra := math.Pi / 2
chart.GenericWedge(g, 30, 20, r, ri, 0.15*ra, 0.5*ra, 1.5, s)
fmt.Printf("\n%s\n", g.String())
chart.GenericWedge(g, 30, 20, r, ri, 1.15*ra, 1.5*ra, 1.5, s)
fmt.Printf("\n%s\n", g.String())
chart.GenericWedge(g, 30, 20, r, ri, 2.15*ra, 2.5*ra, 1.5, s)
fmt.Printf("\n%s\n", g.String())
chart.GenericWedge(g, 30, 20, r, ri, 3.15*ra, 3.5*ra, 1.5, s)
fmt.Printf("\n%s\n", g.String())
// mored than one quadrant
g = initDemoCircle()
chart.GenericWedge(g, 30, 20, r, ri, 0.15*ra, 1.5*ra, 1.5, s)
fmt.Printf("\n%s\n", g.String())
chart.GenericWedge(g, 30, 20, r, ri, 2.15*ra, 3.5*ra, 1.5, s)
fmt.Printf("\n%s\n", g.String())
g = initDemoCircle()
chart.GenericWedge(g, 30, 20, r, ri, 1.5*ra, 2.5*ra, 1.5, s)
fmt.Printf("\n%s\n", g.String())
// all 4 quadrants
g = initDemoCircle()
chart.GenericWedge(g, 30, 20, r, ri, 1.5*ra, 0.5*ra, 1.5, s)
fmt.Printf("\n%s\n", g.String())
}