Alex Schroeder: 2020-05-01 Island map generator and Text Mapper

OK, I’ve added code to my J program to print the map in Text Mapper format to stdout so that I can start taking a look at it. I added printing of a Text Mapper compatible output to my script… And I know how to generate the SVG from the command line… OK, let’s try!

The file I’m working on in JQt can be run from a terminal emulator.

jconsole ‘~user/temp/2.ijs’

To URL-encode the output, more or less:

jconsole ‘~user/temp/2.ijs’ | perl -p -e ‘s/ +$//ge;’ -e ‘s/([^a-zA-Z0-9_.!~()-])/sprintf("%%%02X",ord($1))/ge’

So let’s store that in a variable:

map=$( \ jconsole ‘~user/temp/2.ijs’ \ | perl -p -e ‘s/ +$//ge;’ \ -e ‘s/([^a-zA-Z0-9_.!~()-])/sprintf("%%%02X",ord($1))/ge’)

This is what the viewer shows us:

Image 1

And now to call Text Mapper from the command line:

perl src/hex-mapping/ get \ --header ‘Content-Type:application/x-www-form-urlencoded’ \ --method POST --content “map=$map&type=square” /render \ 2>/dev/null \ > test.svg

Convert the SVG to PNG:

inkscape --without-gui --file=test.svg --export-png=test.png

There you go:

Image 2

Looks like the J preview does not use quite the same colours. Perhaps because of auto-scaling?

Also, hex maps. Different, of course, but still islands. Strangely familiar, but also … wrong … I think? In some weird way? If you don’t know the map using squares, it’s OK. But now that you do, it’s hard to think of this as some sort of torn land. Was there an earth quake that split of this little island on the right?

Image 3

I think what I can also say right now is that I need to work on the colour palette.

Here’s an image of the Galapagos, thanks to the visible earth project at NASA).


Here’s an image of Hawaii, thanks to the visible earth project at NASA).


I’m not sure I want to use these colours but clearly my impression on the ground on Seymore, where I felt everything was black or brown or rusty red does not match these green images from space.

I need to think about this some more.

Source Code

I really need to put it into a repository. :slightly_smiling_face:

mx =: 30 my =: 20 NB. a table of complex numbers c =: (i. my) j./ i. mx NB. starting position of the hotspot hr =: 5 hy =: >. hr % 2 hx =: <. 0.5 + (my % 3) + ? <. 0.5 + my % 3 hc =: hx j. hy NB. a function to compute altitude changes based on where the hotspot is change =: 3 : 0 h =. hr > {. & *. c - y NB. hotspot = 1 u =. 0.8 < ? (my, mx) $ 0 NB. regions atop the hotspot might move up d =. 0.9 < ? (my, mx) $ 0 NB. regions off the hotspot might move down (u * h) - d * -. h ) NB. a biased list of steps to take d =: 1j1 1j1 0j1 0j1 0j1 NB. a table of altitudes a =: (my, mx) $ 0 NB. compute the meandering path of the hotspot across the map NB. compute the change for each step and add it to the altitude NB. no negative values 3 : 0’’ for. i. mx - 2 * hr do. hc =: hc+(?#d){d a =: 0 & >. a + change hc end. ) NB. print map for text-mapper colors =: (‘ocean’, ‘water’, ‘sand’, ‘dark-soil’, ‘soil’, ‘green’, ‘dark-green’,: ‘grey’) 3 : 0’’ for_i. i. my do. for_j. i. mx do. color =. (j { i { a) { colors smoutput (>‘r<0>2.d’ 8!:0 j) , (>‘r<0>2.d’ 8!:0 i) , ’ ', color end. end. ) smoutput ‘include’ NB. display map for visuals decimal =:16"#.‘0123456789abcdef’"_ i.] rgb =: 3 : 0 n =. decimal }. y NB. strip leading # (<.n % 65536), ((<.n % 256) |~ 256), (n |~ 256) ) ocean =: rgb ‘#1c86ee’ NB. 0 water =: rgb ‘#6ebae7’ NB. 1 sand =: rgb ‘#e3bea3’ NB. 2 dry =: rgb ‘#c97457’ NB. 3 nice =: rgb ‘#b0b446’ NB. 4 green =: rgb ‘#77904c’ NB. 5 humid =: rgb ‘#2d501a’ NB. 6 rocky =: rgb ‘#dcddbe’ NB. 7 colors =: (ocean, water, sand, dry, nice, green, humid,: rocky) load ‘viewmat’ colors viewmat a exit 0

Whoa, those are cool! Making a note to check out text mapper. :slight_smile: