From 74fa056d77235a3a5f7baec1367db590e74e0fd7 Mon Sep 17 00:00:00 2001 From: Andinus Date: Wed, 3 Nov 2021 21:09:02 +0530 Subject: Variable frame rate, center the canvas --- lib/Fornax/CLI.rakumod | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'lib') diff --git a/lib/Fornax/CLI.rakumod b/lib/Fornax/CLI.rakumod index 7297903..b2fb629 100644 --- a/lib/Fornax/CLI.rakumod +++ b/lib/Fornax/CLI.rakumod @@ -17,6 +17,7 @@ proto MAIN(|) is export { unless so @*ARGS { put $*USAGE; exit }; {*} } multi sub MAIN( File $input, #= fornax format file (solved) Directory :$output = 'output', #= output directory (existing) + Int :$frame-rate = 1, #= frame rate Bool :$verbose = True, #= verbosity ) is export { my Str @lines = $input.IO.lines; @@ -47,24 +48,27 @@ multi sub MAIN( my Int %cell = width => %CANVAS div %meta, height => %CANVAS div %meta; + my Int $side; + my Int %excess = :0width, :0height; + # Consider width if cells with dimension (width * width) fit # within the canvas, otherwise consider the height. if (%cell * %meta) < %CANVAS { - %cell = %cell; + %excess = abs %CANVAS - %CANVAS; + $side = %cell; } else { - %cell = %cell; + %excess = abs %CANVAS - %CANVAS; + $side = %cell; } enum IterStatus ; for @lines.skip.kv -> $idx, $iter is rw { - my IterStatus $status; given $iter.substr(0, 1) { when '|' { $status = Completed } when '!' { $status = Blocked } default { $status = Walking } - }; # Remove marker. @@ -82,13 +86,16 @@ multi sub MAIN( # Paint the entire canvas white. .rgb: |%C; .rectangle(0, 0, %CANVAS, %CANVAS); - .fill :preserve; + .fill; .stroke; for ^%meta -> $r { for ^%meta -> $c { - .rectangle($c * %cell, $r * %cell, %cell, %cell); + my Int @target = %excess div 2 + $c * $side, + %excess div 2 + $r * $side, + $side, $side; + .rectangle: |@target; given @grid[$r][$c] -> $cell { when $cell eq $VIS|$CUR { .rgba: |%C, 0.64; @@ -102,7 +109,7 @@ multi sub MAIN( .fill :preserve; .rgb: |%C; - .rectangle($c * %cell, $r * %cell, %cell, %cell); + .rectangle: |@target; .stroke; } } @@ -114,7 +121,7 @@ multi sub MAIN( put "[fornax] Generated images."; put "[fornax] Creating a slideshow."; - run «ffmpeg -loglevel error -r 1 -i "$output/\%08d.png" + run «ffmpeg -loglevel error -r "$frame-rate" -i "$output/\%08d.png" -vcodec libx264 -crf 28 -pix_fmt yuv420p "$output/solution.mp4"»; } -- cgit 1.4.1-2-gfad0