v2 / examples / gg / bezier.v
42 lines · 36 sloc · 842 bytes · bbb61ab3687afe512a1fa12492c876d011626107
Raw
1module main
2
3import gg
4
5const points = [f32(200.0), 200.0, 200.0, 100.0, 400.0, 100.0, 400.0, 300.0]
6
7struct App {
8mut:
9 gg &gg.Context = unsafe { nil }
10 steps int = 30
11}
12
13fn main() {
14 mut app := &App{}
15 app.gg = gg.new_context(
16 bg_color: gg.rgb(174, 198, 255)
17 width: 600
18 height: 400
19 window_title: 'Cubic Bézier curve'
20 frame_fn: frame
21 user_data: app
22 )
23 app.gg.run()
24}
25
26fn (mut app App) change(delta int) {
27 app.steps += delta
28 println('app.steps: ${app.steps}')
29}
30
31fn frame(mut app App) {
32 app.gg.begin()
33 app.gg.draw_cubic_bezier_in_steps(points, u32(app.steps), gg.blue)
34 app.gg.draw_cubic_bezier_recursive(points, gg.rgba(255, 50, 50, 150))
35 app.gg.end()
36 if app.gg.pressed_keys[int(gg.KeyCode.down)] {
37 app.change(-1)
38 }
39 if app.gg.pressed_keys[int(gg.KeyCode.up)] {
40 app.change(1)
41 }
42}
43