.
This commit is contained in:
parent
e706ba4767
commit
7112e3cf67
1 changed files with 16 additions and 27 deletions
43
main.odin
43
main.odin
|
@ -1,15 +1,14 @@
|
|||
package main
|
||||
|
||||
import "core:fmt"
|
||||
import "core:os"
|
||||
import "core:strings"
|
||||
import "core:time"
|
||||
|
||||
WIDTH :: 32
|
||||
HEIGHT :: 32
|
||||
WIDTH :: 128
|
||||
HEIGHT :: 128
|
||||
AREA :: WIDTH * HEIGHT
|
||||
|
||||
main :: proc() {
|
||||
fmt.println("hellope")
|
||||
board : [AREA]bool = ---
|
||||
|
||||
// board[0] = true
|
||||
|
@ -18,40 +17,31 @@ main :: proc() {
|
|||
// for x in 4..<14 {
|
||||
// board[x + WIDTH*8] = true
|
||||
// }
|
||||
fmt.print("\e[2J") // clear screen
|
||||
for {
|
||||
fmt.print("\e[u") // reset cursor
|
||||
print_board(&board)
|
||||
bytes := 0
|
||||
err : os.Errno
|
||||
buf : [3]byte
|
||||
for {
|
||||
bytes, err = os.read(os.stdin, buf[:])
|
||||
if bytes > 0 do break
|
||||
}
|
||||
update_board(&board)
|
||||
time.sleep(time.Millisecond * 50)
|
||||
}
|
||||
}
|
||||
|
||||
print_board :: proc(state: ^[AREA]bool){
|
||||
fmt.println(strings.repeat("-", WIDTH))
|
||||
for y := 0; y < HEIGHT; y += 2{
|
||||
line := strings.builder_make()
|
||||
for x in 0..<WIDTH{
|
||||
top := state[x + y * WIDTH]
|
||||
bot := state[x + (y+1) * WIDTH ]
|
||||
if top {
|
||||
if bot{
|
||||
fmt.print("█")
|
||||
}else{
|
||||
fmt.print("▀")
|
||||
}
|
||||
}else{
|
||||
if bot {
|
||||
fmt.print("▄")
|
||||
}else{
|
||||
fmt.print(" ")
|
||||
}
|
||||
c : rune
|
||||
switch {
|
||||
case top && bot: c = '█'
|
||||
case top && !bot: c = '▀'
|
||||
case !top && bot: c = '▄'
|
||||
case: c = ' '
|
||||
}
|
||||
strings.write_rune(&line, c)
|
||||
}
|
||||
fmt.println()
|
||||
fmt.println(strings.to_string(line))
|
||||
}
|
||||
fmt.println()
|
||||
}
|
||||
|
@ -71,9 +61,8 @@ update_board :: proc(state: ^[AREA]bool){
|
|||
}
|
||||
}
|
||||
}
|
||||
cell := state[x + y * WIDTH];
|
||||
cell := state[x + y * WIDTH]
|
||||
new_cell := (count == 3 && !cell) || (cell && count < 5 && count > 2)
|
||||
// fmt.println("count %v, state %v", count, new_cell)
|
||||
new_state[x + y * WIDTH] = new_cell
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue