From f5c4671bfbad96bf346bd7e9a21fc4317b4959df Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Sat, 3 Dec 2022 17:00:20 +0530 Subject: Adds most of the tools --- v_windows/v/old/examples/game_of_life/life_gg.v | 56 +++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 v_windows/v/old/examples/game_of_life/life_gg.v (limited to 'v_windows/v/old/examples/game_of_life/life_gg.v') 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() +} -- cgit v1.2.3