From 1a370006d5222c004383870e0b4cd0054b606478 Mon Sep 17 00:00:00 2001 From: Brendan Hansen Date: Sat, 15 Dec 2018 23:03:04 -0600 Subject: [PATCH] working maze generator example --- data/progs/maze.lgt | 121 +++++++++++++++++++++++++++++++++++++++++ src/christmas_proj.nim | 2 +- 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 data/progs/maze.lgt diff --git a/data/progs/maze.lgt b/data/progs/maze.lgt new file mode 100644 index 0000000..34603c2 --- /dev/null +++ b/data/progs/maze.lgt @@ -0,0 +1,121 @@ +#push_pos { + $m1 = $x + $y * 256 * 256 + + !step_to_linear(0) + !step_to_linear(!get_col() + 1) + + !set_col($m1) + + !step_to_linear(0) + !set_col(!get_col() + 1) + + $x = $m1 % 256 * 256 + $y = $m1 / 256 * 256 +} + +#pop_pos { + !step_to_linear(0) + !step_to_linear(!get_col()) + $m1 = !get_col() + //!set_col(16777215) + + !step_to_linear(0) + !set_col(!get_col() - 1) + $x = $m1 % 256 * 256 + $y = $m1 / 256 * 256 +} + +#get_stack_height { + !push_pos() + !step_to_linear(0) + $m2 = !get_col() - 1 + !pop_pos() + $m2 +} + +//Fills memory with defaults +$y = 20 +while $y < !get_height() { + $x = 0 + while $x < !get_width() { + !set_col(50) + $x = $x + 1 + } + $y = $y + 1 +} + + +$x = 1 +$y = 21 +!push_pos() +!set_col(255) +while !get_stack_height() > 0 { + !pop_pos() + !push_pos() + + $m1 = 0 + $y = $y - 2 + $m1 = $m1 + if !get_col() == 50 { 1 } else { 0 } + $y = $y + 2 + $x = $x - 2 + $m1 = $m1 + if !get_col() == 50 { 1 } else { 0 } + $x = $x + 4 + $m1 = $m1 + if !get_col() == 50 { 1 } else { 0 } + $x = $x - 2 + $y = $y + 2 + $m1 = $m1 + if !get_col() == 50 { 1 } else { 0 } + $y = $y - 2 + + if $m1 { + $m8 = 100 + while $m8 { + //Random direction + $m7 = !random(4) + $m8 = $m8 - 1 + + // dx and dy + $m5 = 0 + $m6 = 0 + + if $m7 == 0 { + $m6 = -2 + } + if $m7 == 1 { + $m5 = 2 + } + if $m7 == 2 { + $m6 = 2 + } + if $m7 == 3 { + $m5 = -2 + } + + if !in_bounds($x + $m5, $y + $m6) { + !push_pos() + !push_pos() + $x = $x + $m5 + $y = $y + $m6 + if !get_col() == 50 { + !set_col(255) + !pop_pos() + $x = $x + $m5 / 2 + $y = $y + $m6 / 2 + !set_col(255) + !pop_pos() + $x = $x + $m5 + $y = $y + $m6 + !push_pos() + $m8 = 0 + } else { + !pop_pos() + !pop_pos() + } + } + } + } else { + !pop_pos() + } + !render() +} + +!say(8008135) diff --git a/src/christmas_proj.nim b/src/christmas_proj.nim index f4783b8..da14717 100644 --- a/src/christmas_proj.nim +++ b/src/christmas_proj.nim @@ -127,7 +127,7 @@ Usage: light ast light (-h | --help) light --version - + Options: -h --help Show this screen. --width= Width of board [default: 64]. -- 2.25.1