-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
110 lines (100 loc) · 2.88 KB
/
example_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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package gog_test
import (
"fmt"
"image/color"
"github.com/setanarut/gog"
)
// 150-frame rotating cubic bezier APNG animation
func Example() {
ctx := gog.New(250, 250)
curve := gog.CubicBezier(100, 95, 50, 300, 190, 88, 140, 200)
curve.SetPos(ctx.Center)
for i := 0; i < 150; i++ {
ctx.Clear(color.Gray{30})
curve.Rotate((gog.Pi * 2) / 150)
ctx.DebugDraw(curve)
ctx.AppendAnimationFrame()
}
// ctx.SaveAPNG("anim.png", 3)
fmt.Println(len(ctx.AnimationFrames))
// Output:
// 150
}
// Creates new line and prints start and end point
func ExampleLine() {
line := gog.Line(gog.Point{X: 0, Y: 0}, gog.Point{X: 25, Y: 80})
fmt.Println(line.Start(), line.End())
// Output:
// {0 0} {25 80}
}
// Get point and tangent angle at time t
func ExamplePath_PointAngleAtTime() {
line := gog.NewPath([]gog.Point{{X: 0, Y: 0}, {X: 10, Y: 10}})
point, angle := line.PointAngleAtTime(0.5)
fmt.Println(point, angle)
// Output:
// {5 5} 0.7853981633974483
}
// Get point and tangent angle at length
func ExamplePath_PointAngleAtLength() {
line := gog.NewPath([]gog.Point{{X: 0, Y: 0}, {X: 10, Y: 10}})
point, angle := line.PointAngleAtLength(line.Length() / 2)
fmt.Println(point, angle)
// Output:
// {5 5} 0.7853981633974483
}
func ExamplePath_InsertAtLength() {
line := gog.NewPath([]gog.Point{{0, 0}, {0, 10}, {0, 20}})
line.InsertAtLength(10.5)
line.PrintPoints()
// Output:
// [{0 0} {0 10} {0 10.5} {0 20}]s
}
// Insert point to path points at index
func ExamplePath_InsertAtIndex() {
line := gog.NewPath([]gog.Point{{0, 0}, {10, 10}})
line.InsertAtIndex(gog.Point{66, 66}, 1)
line.PrintPoints()
// Output:
// [{0 0} {66 66} {10 10}]
}
func ExamplePath_SetAnchor() {
line := gog.NewPath([]gog.Point{{X: 0, Y: 0}, {X: 10, Y: 10}})
fmt.Println(line.Anchor) // Centroid of Path
line.SetAnchor(gog.Point{X: 3, Y: 3})
fmt.Println(line.Anchor)
line.ResetAnchor()
fmt.Println(line.Anchor)
fmt.Println(line.Centroid() == line.Anchor)
// Output:
// {5 5}
// {3 3}
// {5 5}
// true
}
func ExamplePath_RemoveDoubles() {
path := gog.NewPath([]gog.Point{{0, 0}, {77, 77}, {77, 77}, {0, 0}, {0, 0}})
path.RemoveDoubles()
fmt.Println(path.GetPoints())
// Output:
// [{0 0} {77 77} {0 0}]
}
func ExampleStyle() {
myStyle := gog.NewStyle(color.RGBA{255, 0, 0, 255},
color.Gray{128}, 10, gog.RoundCap, gog.RoundJoin)
myStyle2 := gog.Style{
Fill: color.RGBA{255, 255, 0, 255},
Stroke: color.RGBA{255, 0, 255, 255},
LineWidth: 7,
Cap: gog.CubicCap,
Join: gog.BevelJoin,
}
square := gog.Square(gog.P(10, 10), 50).SetStyle(myStyle)
square2 := gog.Square(gog.P(10, 10), 50)
square2.Style = myStyle2
square2.SetFill(color.RGBA{0, 255, 255, 255})
fmt.Printf("%+v\n%+v", square.Style, square2.Style)
// Output:
// {Fill:{R:255 G:0 B:0 A:255} Stroke:{Y:128} LineWidth:10 Cap:2 Join:1}
// {Fill:{R:0 G:255 B:255 A:255} Stroke:{R:255 G:0 B:255 A:255} LineWidth:7 Cap:3 Join:2}
}