2019-11-23 14:33:25 +01:00
|
|
|
module main
|
|
|
|
|
|
|
|
import gg
|
|
|
|
import gx
|
|
|
|
import automaton
|
|
|
|
|
|
|
|
const (
|
2020-05-22 17:36:09 +02:00
|
|
|
screen_width = 800
|
|
|
|
screen_height = 600
|
|
|
|
filled_color = gx.blue
|
2019-11-23 14:33:25 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
fn new_graphics() &gg.GG {
|
|
|
|
glfw.init_glfw()
|
|
|
|
return gg.new_context(gg.Cfg{
|
2020-05-22 17:36:09 +02:00
|
|
|
width: screen_width
|
|
|
|
height: screen_height
|
2019-11-23 14:33:25 +01:00
|
|
|
use_ortho: true
|
|
|
|
create_window: true
|
|
|
|
resizable: false
|
|
|
|
window_title: 'v life (with gg, glfw, gx)'
|
|
|
|
window_user_ptr: 0
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const (
|
|
|
|
graphics = new_graphics()
|
|
|
|
)
|
|
|
|
|
|
|
|
[live]
|
|
|
|
fn print_automaton(a &automaton.Automaton){
|
2020-05-22 19:00:46 +02:00
|
|
|
gg.clear(gx.white)
|
2019-11-23 14:33:25 +01:00
|
|
|
square_size := 18
|
|
|
|
for y := 1; y<a.field.maxy; y++ {
|
|
|
|
for x := 1; x<a.field.maxx; x++ {
|
|
|
|
cell := a.field.get(x,y)
|
|
|
|
if cell == 1 {
|
2020-06-02 19:47:28 +02:00
|
|
|
graphics.draw_rect(f32(square_size*x), f32(square_size*y), f32(square_size),
|
|
|
|
f32(square_size), filled_color)
|
2019-11-23 14:33:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
mut a := automaton.gun()
|
|
|
|
for {
|
|
|
|
if graphics.window.should_close() { graphics.window.destroy() break }
|
|
|
|
gg.post_empty_event() // needed so the animation does not stop
|
|
|
|
///////////////////////////////////////////////
|
|
|
|
a.update()
|
2020-05-22 17:36:09 +02:00
|
|
|
print_automaton(a)
|
2019-11-23 14:33:25 +01:00
|
|
|
graphics.render()
|
|
|
|
}
|
|
|
|
}
|