This commit is contained in:
Crispy 2024-05-02 13:09:40 +02:00
parent e706ba4767
commit 7112e3cf67

View file

@ -1,15 +1,14 @@
package main package main
import "core:fmt" import "core:fmt"
import "core:os"
import "core:strings" import "core:strings"
import "core:time"
WIDTH :: 32 WIDTH :: 128
HEIGHT :: 32 HEIGHT :: 128
AREA :: WIDTH * HEIGHT AREA :: WIDTH * HEIGHT
main :: proc() { main :: proc() {
fmt.println("hellope")
board : [AREA]bool = --- board : [AREA]bool = ---
// board[0] = true // board[0] = true
@ -18,40 +17,31 @@ main :: proc() {
// for x in 4..<14 { // for x in 4..<14 {
// board[x + WIDTH*8] = true // board[x + WIDTH*8] = true
// } // }
fmt.print("\e[2J") // clear screen
for { for {
fmt.print("\e[u") // reset cursor
print_board(&board) 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) update_board(&board)
time.sleep(time.Millisecond * 50)
} }
} }
print_board :: proc(state: ^[AREA]bool){ print_board :: proc(state: ^[AREA]bool){
fmt.println(strings.repeat("-", WIDTH))
for y := 0; y < HEIGHT; y += 2{ for y := 0; y < HEIGHT; y += 2{
line := strings.builder_make()
for x in 0..<WIDTH{ for x in 0..<WIDTH{
top := state[x + y * WIDTH] top := state[x + y * WIDTH]
bot := state[x + (y+1) * WIDTH ] bot := state[x + (y+1) * WIDTH ]
if top { c : rune
if bot{ switch {
fmt.print("█") case top && bot: c = '█'
}else{ case top && !bot: c = '▀'
fmt.print("▀") case !top && bot: c = '▄'
case: c = ' '
} }
}else{ strings.write_rune(&line, c)
if bot {
fmt.print("▄")
}else{
fmt.print(" ")
} }
} fmt.println(strings.to_string(line))
}
fmt.println()
} }
fmt.println() 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) 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 new_state[x + y * WIDTH] = new_cell
} }
} }