v / examples / game_of_life / life_gg.v
52 lines · 46 sloc · 940 bytes · e2e5cf8db56f3562c7baa735061690be936bdf3e
Raw
1module main
2
3import gg
4import automaton
5
6const screen_width = 800
7const screen_height = 600
8const filled_color = gg.blue
9
10@[live]
11fn 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
24struct App {
25mut:
26 gg &gg.Context = unsafe { nil }
27 a automaton.Automaton
28}
29
30fn frame(mut app App) {
31 app.gg.begin()
32 app.a.update()
33 print_automaton(app)
34 app.gg.end()
35}
36
37fn 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