-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (53 loc) · 1.32 KB
/
main.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
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/icyrogue/golottie"
)
//gocyclo:ignore
func main() {
// Initialize a new animation from file
a, err := os.ReadFile("../../misc/test.json")
if err != nil {
log.Fatal(err)
}
// Use default template to create HTML needed for rendering
animation, err := golottie.NewAnimation(a).WithDefaultTemplate()
if err != nil {
log.Fatal(err)
}
// NewContext creates a new chromedp context with an error stack
ctx, cancel := golottie.NewContext(context.Background())
defer cancel()
// Create a new render instance from context and set the animation to render
instance := golottie.New(ctx)
err = instance.SetAnimation(animation)
if err != nil {
log.Fatal(err)
}
// Advance the current frame and render it as PNG
var frame int
for instance.NextFrame() {
// frame++
log.Println("Rendering frame", frame)
// The render result will be stored in the frame buffer
var buf []byte
err := instance.RenderFrame(&buf)
if err != nil {
log.Fatal(err)
}
err = os.WriteFile(fmt.Sprintf("../render/%04d.png", frame), buf, 0o644)
if err != nil {
log.Fatal(err)
}
}
// Check the context error stack
if err = ctx.Errors[:1][0]; err != nil {
// Instance will return EOF at the end of animation frames
if err != golottie.EOF {
log.Fatal(err)
}
}
}