aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mapGen/README.md22
-rwxr-xr-xmapGen/mapGen.sh17
2 files changed, 23 insertions, 16 deletions
diff --git a/mapGen/README.md b/mapGen/README.md
index 242b5d4..10078e2 100644
--- a/mapGen/README.md
+++ b/mapGen/README.md
@@ -15,7 +15,7 @@ xxxxx
## Dependencies
- A POSIX-compliant shell (`bash`, `dash`, `sh`, `zsh`)
-- ImageMagick
+- [ImageMagick](https://imagemagick.org/index.php)
- Tools expected in a Unix environment: `grep`, `sed`, `awk`
## Motivation
@@ -26,10 +26,11 @@ The want for Vim to be a map maker.
Given a text file in which each character represents a cell, have a script draw that map.
-`mapGen.sh` takes as input a text file with a block of text which ideally has a block of characters
-with no missing ones. It also takes a folder in which tile images are supposed to be. For each
-character in the file, it randomly takes one image in that folder which name starts with that
-characters and creates an image from the text file.
+`mapGen.sh` takes as input a text file which ideally has a block of characters of any size but of
+rectangular shape with no missing ones. It also takes a folder in which tile images are supposed to
+be. For each character in the file it randomly takes one image in that folder which name starts
+with that character and composes it into the map image with the help of the `convert` command from
+ImageMagick.
## Examples
@@ -71,12 +72,15 @@ XXXXXXXXXooXXXXXXXXX
## Usage
```
-mapGen.sh [-s SIZE] [-f TILE_FOLDER] SOURCE_FILE
+mapGen.sh [-s SIZE] [-f TILE_FOLDER] [-o OUTPUT_FILE] SOURCE_FILE
```
-Where `SIZE` is the size of the tile images in pixels (default 8), `TILE_FOLDER` is the folder
-where the tile images are stored (default `./tiles`) and `SOURCE_FILE` is the text file with the
-layout of the map.
+Where
+
+- `SIZE` is the size of the tile images in pixels (default 8),
+- `TILE_FOLDER` is the folder where the tile images are stored (default `./tiles`),
+- `OUTPUT_FILE` is the path to the resulting image (default `out.jpg`),
+- and `SOURCE_FILE` is the text file with the layout of the map.
## Possibilities
diff --git a/mapGen/mapGen.sh b/mapGen/mapGen.sh
index bf4bac3..0d77637 100755
--- a/mapGen/mapGen.sh
+++ b/mapGen/mapGen.sh
@@ -4,13 +4,12 @@
#
# Generate a map with ImageMagick from an input text file
#
-# Usage: mapGen.sh [-s SIZE] [-f TILE_FOLDER] SOURCE_FILE
-
-usageMsg="Usage: mapGen.sh [-s SIZE] [-f TILE_FOLDER] SOURCE_FILE"
+# Usage: mapGen.sh [-s SIZE] [-f TILE_FOLDER] [-o OUTPUT_FILE] SOURCE_FILE
+usageMsg="Usage: mapGen.sh [-s SIZE] [-f TILE_FOLDER] [-o OUTPUT_FILE] SOURCE_FILE"
cellSize=8
-
tilesDir="./tiles"
+outputFile="out.jpg"
while echo "$1" | grep '^-' >/dev/null; do
case "$1" in
@@ -24,6 +23,10 @@ while echo "$1" | grep '^-' >/dev/null; do
tilesDir="$2"
shift 2
;;
+ "-o")
+ [ -z "$2" ] && echo "Missing argument for -o. $usageMsg" >&2 && exit 1
+ outputFile="$2"
+ shift 2
esac
done
@@ -42,7 +45,7 @@ width=$((width*cellSize))
echo $width $height
-convert -size "$width"x"$height" xc:cyan out.jpg
+convert -size "$width"x"$height" xc:cyan "$outputFile"
row=0
col=0
@@ -53,8 +56,8 @@ while read line; do
tileFile="$(find $tilesDir | sed 's|.*/||' | grep "^$char" | shuf | sed 1q)"
tileFile="${tilesDir}/${tileFile}"
echo "$tileFile" | wc -l | grep 1 >/dev/null || continue
- convert out.jpg "$tileFile" -geometry +"$col"+"$row" -composite out.jpg ||
- convert out.jpg -fill red -draw "point $col,$row" out.jpg
+ convert "$outputFile" "$tileFile" -geometry +"$col"+"$row" -composite "$outputFile" ||
+ convert "$outputFile" -fill red -draw "point $col,$row" "$outputFile"
col=$((col+cellSize))
done)
row=$((row+cellSize))