2019-11-23 16:33:25 +03:00
|
|
|
module main
|
|
|
|
|
|
|
|
import gg
|
|
|
|
import glfw
|
|
|
|
import gx
|
|
|
|
import automaton
|
|
|
|
|
|
|
|
const (
|
2020-05-22 18:36:09 +03:00
|
|
|
screen_width = 800
|
|
|
|
screen_height = 600
|
|
|
|
filled_color = gx.blue
|
2019-11-23 16:33:25 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
fn new_graphics() &gg.GG {
|
|
|
|
glfw.init_glfw()
|
|
|
|
return gg.new_context(gg.Cfg{
|
2020-05-22 18:36:09 +03:00
|
|
|
width: screen_width
|
|
|
|
height: screen_height
|
2019-11-23 16:33:25 +03: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 20:00:46 +03:00
|
|
|
gg.clear(gx.white)
|
2019-11-23 16:33:25 +03: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 {
|
|
|
|
graphics.draw_rect( square_size*x, square_size*y, square_size, square_size, filled_color )
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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 18:36:09 +03:00
|
|
|
print_automaton(a)
|
2019-11-23 16:33:25 +03:00
|
|
|
graphics.render()
|
|
|
|
}
|
|
|
|
}
|