2019-11-23 14:33:25 +01:00
|
|
|
module main
|
|
|
|
|
|
|
|
import gg
|
|
|
|
import gx
|
|
|
|
import automaton
|
|
|
|
|
|
|
|
const (
|
2020-10-26 12:14:21 +01:00
|
|
|
screen_width = 800
|
2020-05-22 17:36:09 +02:00
|
|
|
screen_height = 600
|
2020-10-26 12:14:21 +01:00
|
|
|
filled_color = gx.blue
|
2019-11-23 14:33:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
[live]
|
2020-10-26 12:14:21 +01:00
|
|
|
fn print_automaton(app &App) {
|
2019-11-23 14:33:25 +01:00
|
|
|
square_size := 18
|
2020-10-26 12:14:21 +01: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 14:33:25 +01:00
|
|
|
if cell == 1 {
|
2020-10-26 12:14:21 +01:00
|
|
|
app.gg.draw_rect(f32(square_size * x), f32(square_size * y), f32(square_size),
|
2020-06-02 19:47:28 +02:00
|
|
|
f32(square_size), filled_color)
|
2019-11-23 14:33:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-26 12:14:21 +01: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 14:33:25 +01:00
|
|
|
fn main() {
|
2020-10-26 12:14:21 +01:00
|
|
|
mut app := App{
|
|
|
|
gg: 0
|
|
|
|
a: automaton.gun()
|
2019-11-23 14:33:25 +01:00
|
|
|
}
|
2021-04-20 16:16:35 +02:00
|
|
|
app.gg = gg.new_context(
|
2020-10-26 12:14:21 +01: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 16:16:35 +02:00
|
|
|
)
|
2020-10-26 12:14:21 +01:00
|
|
|
app.gg.run()
|
2019-11-23 14:33:25 +01:00
|
|
|
}
|