Converting bitmap images to map terrain.

willbir · 12563

willbir

  • Community Guild
  • *****
    • Posts: 122
Converting bitmap images to map terrain.
on: February 22, 2017, 05:54:40 am
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).

« Last Edit: February 24, 2017, 12:27:30 pm by willbir »



FOXX

  • Community Guild
  • *****
    • Posts: 1371
  • Just Breathe
Re: Converting bitmap images to map terrain.
Reply #1 on: February 24, 2017, 12:25:46 pm
Is this also possible for Particle Fleet?? [PRPL]

The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS


planetfall

  • Sr. Member
  • ****
    • Posts: 1049
  • In radians may we find vectory!
Re: Converting bitmap images to map terrain.
Reply #2 on: February 24, 2017, 01:08:51 pm
Excellent tool you have here. Thanks for sharing it!

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.

"Build a ladder to the moon" is simple as a sentence, but actually doing it is not.


Stickman

  • Community Guild
  • *****
    • Posts: 136
Re: Converting bitmap images to map terrain.
Reply #3 on: February 24, 2017, 01:35:11 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:
Code: [Select]
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

  • Community Guild
  • *****
    • Posts: 3456
  • (Pusillanimous)
Re: Converting bitmap images to map terrain.
Reply #4 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.

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


willbir

  • Community Guild
  • *****
    • Posts: 122
Re: Converting bitmap images to map terrain.
Reply #5 on: February 24, 2017, 05:43:38 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

  • Community Guild
  • *****
    • Posts: 3456
  • (Pusillanimous)
Re: Converting bitmap images to map terrain.
Reply #6 on: February 24, 2017, 06:04:26 pm
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

  • Community Guild
  • *****
    • Posts: 1371
  • Just Breathe
Re: Converting bitmap images to map terrain.
Reply #7 on: February 24, 2017, 07:32:37 pm
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.
« Last Edit: February 24, 2017, 08:09:42 pm by FOXX »

The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS


willbir

  • Community Guild
  • *****
    • Posts: 122
Re: Converting bitmap images to map terrain.
Reply #8 on: February 25, 2017, 04:26:54 am
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.


« Last Edit: February 25, 2017, 04:28:45 am by willbir »



FOXX

  • Community Guild
  • *****
    • Posts: 1371
  • Just Breathe
Re: Converting bitmap images to map terrain.
Reply #9 on: February 25, 2017, 07:16:43 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

  • Community Guild
  • *****
    • Posts: 1371
  • Just Breathe
Re: Converting bitmap images to map terrain.
Reply #10 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']

You can turn the image upside down but maybe it;s better if the script gets updated for this.
« Last Edit: February 25, 2017, 02:28:12 pm by FOXX »

The FPAF
For My Maps and Ships!
Including  CUSTOM MODULE MAPS & SHIPS


willbir

  • Community Guild
  • *****
    • Posts: 122
Re: Converting bitmap images to map terrain.
Reply #11 on: February 25, 2017, 02:29:24 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

  • Community Guild
  • *****
    • Posts: 1371
  • Just Breathe
Re: Converting bitmap images to map terrain.
Reply #12 on: February 25, 2017, 02:44:55 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

  • Community Guild
  • *****
    • Posts: 3456
  • (Pusillanimous)
Re: Converting bitmap images to map terrain.
Reply #13 on: February 25, 2017, 06:32:58 pm
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

  • Community Guild
  • *****
    • Posts: 1371
  • Just Breathe
Re: Converting bitmap images to map terrain.
Reply #14 on: February 25, 2017, 06:59:15 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