aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/examples/game_of_life/life_gg.v
diff options
context:
space:
mode:
Diffstat (limited to 'v_windows/v/old/examples/game_of_life/life_gg.v')
-rw-r--r--v_windows/v/old/examples/game_of_life/life_gg.v56
1 files changed, 56 insertions, 0 deletions
diff --git a/v_windows/v/old/examples/game_of_life/life_gg.v b/v_windows/v/old/examples/game_of_life/life_gg.v
new file mode 100644
index 0000000..2f45017
--- /dev/null
+++ b/v_windows/v/old/examples/game_of_life/life_gg.v
@@ -0,0 +1,56 @@
+module main
+
+import gg
+import gx
+import automaton
+
+const (
+ screen_width = 800
+ screen_height = 600
+ filled_color = gx.blue
+)
+
+[live]
+fn print_automaton(app &App) {
+ square_size := 18
+ for y := 1; y < app.a.field.maxy; y++ {
+ for x := 1; x < app.a.field.maxx; x++ {
+ cell := app.a.field.get(x, y)
+ if cell == 1 {
+ app.gg.draw_rect(f32(square_size * x), f32(square_size * y), f32(square_size),
+ f32(square_size), filled_color)
+ }
+ }
+ }
+}
+
+struct App {
+mut:
+ gg &gg.Context
+ a automaton.Automaton
+}
+
+fn frame(mut app App) {
+ app.gg.begin()
+ app.a.update()
+ print_automaton(app)
+ app.gg.end()
+}
+
+fn main() {
+ mut app := App{
+ gg: 0
+ a: automaton.gun()
+ }
+ app.gg = gg.new_context(
+ bg_color: gx.white
+ frame_fn: frame
+ user_data: &app
+ width: screen_width
+ height: screen_height
+ create_window: true
+ resizable: false
+ window_title: 'v life (with gg, gx)'
+ )
+ app.gg.run()
+}