aboutsummaryrefslogtreecommitdiff
path: root/v_windows/v/old/examples/game_of_life/life_gg.v
blob: 2f45017c437ccb12f8b6c2b5395b10110d0e055d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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()
}