2019-11-23 16:33:25 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import gg
|
|
|
|
import gx
|
|
|
|
import automaton
|
|
|
|
|
|
|
|
const (
|
2020-10-26 14:14:21 +03:00
|
|
|
screen_width = 800
|
2020-05-22 18:36:09 +03:00
|
|
|
screen_height = 600
|
2020-10-26 14:14:21 +03:00
|
|
|
filled_color = gx.blue
|
2019-11-23 16:33:25 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
[live]
|
2020-10-26 14:14:21 +03:00
|
|
|
fn print_automaton(app &App) {
|
2019-11-23 16:33:25 +03:00
|
|
|
square_size := 18
|
2020-10-26 14:14:21 +03:00
|
|
|
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)
|
2019-11-23 16:33:25 +03:00
|
|
|
if cell == 1 {
|
2020-10-26 14:14:21 +03:00
|
|
|
app.gg.draw_rect(f32(square_size * x), f32(square_size * y), f32(square_size),
|
2020-06-02 20:47:28 +03:00
|
|
|
f32(square_size), filled_color)
|
2019-11-23 16:33:25 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 14:14:21 +03:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
|
2019-11-23 16:33:25 +03:00
|
|
|
fn main() {
|
2020-10-26 14:14:21 +03:00
|
|
|
mut app := App{
|
|
|
|
gg: 0
|
|
|
|
a: automaton.gun()
|
2019-11-23 16:33:25 +03:00
|
|
|
}
|
2021-04-20 17:16:35 +03:00
|
|
|
app.gg = gg.new_context(
|
2020-10-26 14:14:21 +03:00
|
|
|
bg_color: gx.white
|
|
|
|
frame_fn: frame
|
|
|
|
user_data: &app
|
|
|
|
width: screen_width
|
|
|
|
height: screen_height
|
|
|
|
use_ortho: true
|
|
|
|
create_window: true
|
|
|
|
resizable: false
|
|
|
|
window_title: 'v life (with gg, gx)'
|
2021-04-20 17:16:35 +03:00
|
|
|
)
|
2020-10-26 14:14:21 +03:00
|
|
|
app.gg.run()
|
2019-11-23 16:33:25 +03:00
|
|
|
}
|