-
Notifications
You must be signed in to change notification settings - Fork 1
/
animatedclipping.go
60 lines (51 loc) · 1.2 KB
/
animatedclipping.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
package main
import (
"image/color"
"math"
"time"
"gioui.org/app"
"gioui.org/f32"
"gioui.org/io/system"
"gioui.org/op"
"gioui.org/op/clip"
"gioui.org/op/paint"
)
func main() {
go func() {
w := app.NewWindow()
ops := new(op.Ops)
for e := range w.Events() {
if e, ok := e.(system.FrameEvent); ok {
ops.Reset()
// START OMIT
square := f32.Rectangle{Max: f32.Point{X: 500, Y: 500}}
radius := animateRadius(e.Now, 250)
// Position
op.Affine(f32.Affine2D{}.Offset(f32.Point{ // HLdraw
X: 100, // HLdraw
Y: 100, // HLdraw
})).Add(ops) // HLdraw
// Color
paint.ColorOp{Color: color.RGBA{A: 0xff, G: 0xcc}}.Add(ops) // HLdraw
// Clip corners
clip.RRect{Rect: square,
NE: radius, NW: radius, SE: radius, SW: radius}.Op(ops).Add(ops) // HLdraw
// Draw
paint.PaintOp{}.Add(ops) // HLdraw
// Animate
op.InvalidateOp{}.Add(ops) // HLdraw
// Submit operations to the window.
e.Frame(ops) // HLdraw
// END OMIT
}
}
}()
app.Main()
}
// END RR OMIT
var start = time.Now()
func animateRadius(t time.Time, max float32) float32 {
dt := t.Sub(start).Seconds()
radius := math.Abs(math.Sin(dt))
return float32(radius) * max
}