Skip to content

Canvas Animation / Render loop #1407

Answered by kkoreilly
0pcom asked this question in Q&A
Discussion options

You must be logged in to vote

Here is a simple example of a canvas animation that I have added to the documentation in #1321:

t := 0
c := core.NewCanvas(b).SetDraw(func(pc *paint.Context) {
    pc.DrawCircle(0.5, 0.5, float32(t%60)/120)
    pc.FillStyle.Color = colors.Scheme.Success.Base
    pc.Fill()
})
go func() {
    for range time.Tick(time.Second/60) {
        c.NeedsRender()
        t++
    }
}()

That makes a circle with a changing size based on a time variable incremented in a render loop. If that example is not sufficient, I can definitely help you with the use cases you mentioned; they should absolutely be possible. I am improving the documentation for this in #1321 as mentioned above, and I will continue to …

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by 0pcom
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants