Converting bitmap images to map terrain.

Started by willbir, February 22, 2017, 05:54:40 AM

Previous topic - Next topic

willbir

This has probably been done before but I've been experimenting with converting bitmap images to map terrain. The way I've done it is using some JavaScript to read an image and then use that data to generate crpl code which when copied to a map and run will modify the terrain to reproduce the image. The code is attached if anyone else wants to have a go with it (if run locally chrome throws an error but IE works).


FOXX

Is this also possible for Particle Fleet?? [PRPL]
The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS

planetfall

Excellent tool you have here. Thanks for sharing it!

Quote from: FOXX on February 24, 2017, 12:25:46 PM
Is this also possible for Particle Fleet?? [PRPL]

In theory, you'd just have to change SetTerrain to SetLand.
Pretty sure I'm supposed to be banned, someone might want to get on that.

Quote from: GoodMorning on December 01, 2016, 05:58:30 PM"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.

Stickman

Quote from: planetfall on February 24, 2017, 01:08:51 PM
In theory, you'd just have to change SetTerrain to SetLand.

FOXX led me here to test it and this simple change works.
To get better results, you need to change a line in the html file like that:

h= Math.floor((0.299*r + 0.587*g + 0.114*b)/51.2);

Changing from 25.6 to 51.2 seems to convert 10 CW3 land heights to 5 PF land heights nicely.

Amazingly cool tool
=====> This is a moderately pointy stick. You need to poke me with it once in three days if you need PRPL from me

GoodMorning

Nice. Using IE for a lack of security on a local sandbox application is not new, but... caution advised.
A narrative is a lightly-marked path to another reality.

willbir

Quote from: GoodMorning on February 24, 2017, 05:29:32 PM
Nice. Using IE for a lack of security on a local sandbox application is not new, but... caution advised.

If you look at the code you can verify there is nothing nefarious going on, the error is due to Chrome considering local files cross-origin so the canvas becomes tainted.

GoodMorning

I didn't say it wasn't reasonable, only that there's a reason it is the way it is.

Good tool.
A narrative is a lightly-marked path to another reality.

FOXX

#7
Yeah, this is a really cool tool. I am busy with a lot of things now but after i finish that, this will be a point of interest.
'I can see little figures in space' :)

I have tried this with some randome images i got from internet. [see attachments]
If there is a way to set x and y points and maybe a rotate option that would be great. [or is that already in the script?]

I think with some scripting this can be even more great.
The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS

willbir

#8
Quote from: FOXX on February 24, 2017, 07:32:37 PM
I have tried this with some randome images i got from internet. [see attachments]
If there is a way to set x and y points and maybe a rotate option that would be great. [or is that already in the script?]


You can do that in Photoshop before you create the terrain, if you move the crpl line "I <-f <-h setterrain" just above the endif then transparent parts of an image will leave the terrain unchanged.

I find vector images like these produce good results.



FOXX

Quote from: willbir on February 25, 2017, 04:26:54 AM
You can do that in Photoshop before you create the terrain, if you move the crpl line "I <-f <-h setterrain" just above the endif then transparent parts of an image will leave the terrain unchanged.

I find vector images like these produce good results.
Thanks for the tip and link !!
The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS

FOXX

#10
The land created in Particle Fleet is upside down :(
Can somebody look at the script to change this please.

[I don't want the fish to be 'dead']

You can turn the image upside down but maybe it;s better if the script gets updated for this.
The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS

willbir

Quote from: FOXX on February 25, 2017, 02:19:49 PM
The land created in Particle Fleet is upside down :(
Can somebody look at the script to change this please.

[I don't want the fish to be 'dead']

changing the line
I <-f <-h setterrain
to
I <-imageY <-f sub <-h setterrain

should flip it

FOXX

Quote from: willbir on February 25, 2017, 02:29:24 PM
changing the line
I <-f <-h setterrain
to
I <-imageY <-f sub <-h setterrain

should flip it
Just tried it, works perfect :)

Now the thing is that by default the land sticks to the SouthWest corner. Is there a way to set coordinates?
Or at least an option or scripting for setting the spawnpoint of the land to the North?
The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS

GoodMorning

Making the land position be set relative to CurrentX and CurrentY will do it.
A narrative is a lightly-marked path to another reality.

FOXX

Quote from: GoodMorning on February 25, 2017, 06:32:58 PM
Making the land position be set relative to CurrentX and CurrentY will do it.
Thanks GM.
The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS