| 1 | module main |
| 2 | |
| 3 | import gg |
| 4 | import automaton |
| 5 | |
| 6 | const screen_width = 800 |
| 7 | const screen_height = 600 |
| 8 | const filled_color = gg.blue |
| 9 | |
| 10 | @[live] |
| 11 | fn print_automaton(app &App) { |
| 12 | square_size := 18 |
| 13 | for y := 1; y < app.a.field.maxy; y++ { |
| 14 | for x := 1; x < app.a.field.maxx; x++ { |
| 15 | cell := app.a.field.get(x, y) |
| 16 | if cell == 1 { |
| 17 | app.gg.draw_rect_filled(f32(square_size * x), f32(square_size * y), |
| 18 | f32(square_size), f32(square_size), filled_color) |
| 19 | } |
| 20 | } |
| 21 | } |
| 22 | } |
| 23 | |
| 24 | struct App { |
| 25 | mut: |
| 26 | gg &gg.Context = unsafe { nil } |
| 27 | a automaton.Automaton |
| 28 | } |
| 29 | |
| 30 | fn frame(mut app App) { |
| 31 | app.gg.begin() |
| 32 | app.a.update() |
| 33 | print_automaton(app) |
| 34 | app.gg.end() |
| 35 | } |
| 36 | |
| 37 | fn main() { |
| 38 | mut app := App{ |
| 39 | a: automaton.gun() |
| 40 | } |
| 41 | app.gg = gg.new_context( |
| 42 | bg_color: gg.white |
| 43 | frame_fn: frame |
| 44 | user_data: &app |
| 45 | width: screen_width |
| 46 | height: screen_height |
| 47 | create_window: true |
| 48 | resizable: false |
| 49 | window_title: 'v life (with gg)' |
| 50 | ) |
| 51 | app.gg.run() |
| 52 | } |
| 53 | |