-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathease_test.go
34 lines (28 loc) · 982 Bytes
/
ease_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
package mergi_test
import (
"testing"
"image"
"github.com/noelyahan/impexp"
"github.com/noelyahan/mergi"
)
func TestEase(t *testing.T) {
// Load background and the square images
square, _ := mergi.Import(impexp.NewFileImporter("./testdata/square.jpg"))
bg, _ := mergi.Import(impexp.NewFileImporter("./testdata/white_bg.jpg"))
// Init images frames to add applied ease frames
frames := make([]image.Image, 0)
// Init the limts of the Ease
to := bg.Bounds().Max.X - square.Bounds().Max.X
posY := bg.Bounds().Max.Y/2 - square.Bounds().Max.Y/2
speed := 4
// Ease from 0 to width of background
for i := 0; i < to; i += speed {
// Apply Easeing function InBounce
posX := mergi.Ease(float64(i), 0, float64(to), mergi.InBounce)
img, _ := mergi.Watermark(square, bg, image.Pt(int(posX), posY))
frames = append(frames, img)
}
// For preview example, save as a gif
gif, _ := mergi.Animate(frames, 1)
mergi.Export(impexp.NewAnimationExporter(gif, "out.gif"))
}