| 1 | module main |
| 2 | |
| 3 | import gg |
| 4 | |
| 5 | const points = [f32(200.0), 200.0, 200.0, 100.0, 400.0, 100.0, 400.0, 300.0] |
| 6 | |
| 7 | struct App { |
| 8 | mut: |
| 9 | gg &gg.Context = unsafe { nil } |
| 10 | steps int = 30 |
| 11 | } |
| 12 | |
| 13 | fn 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 | |
| 26 | fn (mut app App) change(delta int) { |
| 27 | app.steps += delta |
| 28 | println('app.steps: ${app.steps}') |
| 29 | } |
| 30 | |
| 31 | fn 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 | |