Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //DESCRIPTION:
- //This program (for Processing 3: http://processing.org) adds black, two-pixel (or one-pixel) borders between any two countries, but not between a country and water or between a country and wasteland.
- //It's been tested to work on any automatically-exported map from Crusader Kings II, Europa Universalis IV, or Victoria II (after that map has been converted from BMP to PNG format, if necessary), as well as on PNG-format province maps.
- //It also presumably works on maps exported from other games, but I haven't gotten around to testing them yet, since those three are the only ones that I play.
- //INSTRUCTIONS:
- //1. Make sure that ONLY the RELEVANT color settings below are active. If you're using a CK2 map, comment out the EU4 and V2 lines; if you're using an EU4 map, comment out the CK2 and V2 lines; etc.
- //2. Rename your screenshot to "map.png" and copy it into a folder named "data" in the same directory as this program.
- //3. Run the program and wait for a few seconds.
- //4. Open the "output" folder in the same directory as this program to see the final result!
- PImage map0;
- //color water=color(51,67,85);//CK2
- //color wasteland=color(38,38,38);//CK2
- //color uncolonized=color(38,38,38);//CK2
- color water=color(68,107,163);//EU4
- color wasteland=color(94,94,94);//EU4
- color uncolonized=color(150,150,150);//EU4
- //color water=color(255,255,255);//V2
- //color wasteland=color(0,0,0);//V2--not applicable
- //color uncolonized=color(0,0,0);//V2
- int expand=0;//Set to 0 if you don't want colors to bleed into the wasteland (recommended for V2)
- int wastelandBorders=0;//Set to 0 if you don't want black borders to appear where wastelands would be (meant for disputed "borders" in the middle of a desert--doesn't work too well with narrow mountain ranges)
- int borderWidth=3;//Set to the desired border width, in pixels
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- //-----------------------------------------------------------------------------
- void setup(){
- map0=loadImage("map.png");//Actually "data/map.png"
- map0.loadPixels();
- }
- void draw(){
- //1. Load pixels
- color[][] mapPixels=new color[map0.width][map0.height];
- color[][] mapPixels2=new color[map0.width][map0.height];
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- mapPixels[x][y]=map0.pixels[x+y*map0.width];
- mapPixels2[x][y]=map0.pixels[x+y*map0.width];
- }
- }
- //1.5. If the uncolonized-land color is black, change it to EU4's gray. Black land interferes with borders.
- if(uncolonized==color(0,0,0)){
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- if(mapPixels[x][y]==uncolonized){
- mapPixels[x][y]=color(150,150,150);
- mapPixels2[x][y]=color(150,150,150);
- }
- }
- }
- uncolonized=color(150,150,150);
- }
- //2. Expand color into wastelands
- color[][] mapPixels3=new color[map0.width][map0.height];//Preserves original wastelands
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- mapPixels3[x][y]=mapPixels[x][y];
- }
- }
- if(expand==1){
- int expansionOccurred=1;
- while(expansionOccurred==1){
- expansionOccurred=0;
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- if(mapPixels[x][y]==wasteland){
- if(x+1<map0.width&&mapPixels[x+1][y]!=wasteland&&mapPixels[x+1][y]!=water){//000
- mapPixels2[x][y]=mapPixels[x+1][y];
- expansionOccurred=1;
- }else if(x+1<map0.width&&y+1<map0.height&&mapPixels[x+1][y+1]!=wasteland&&mapPixels[x+1][y+1]!=water){//045
- mapPixels2[x][y]=mapPixels[x+1][y+1];
- expansionOccurred=1;
- }else if(y+1<map0.height&&mapPixels[x][y+1]!=wasteland&&mapPixels[x][y+1]!=water){//090
- mapPixels2[x][y]=mapPixels[x][y+1];
- expansionOccurred=1;
- }else if(x-1>-1&&y+1<map0.height&&mapPixels[x-1][y+1]!=wasteland&&mapPixels[x-1][y+1]!=water){//135
- mapPixels2[x][y]=mapPixels[x-1][y+1];
- expansionOccurred=1;
- }else if(x-1>-1&&mapPixels[x-1][y]!=wasteland&&mapPixels[x-1][y]!=water){//180
- mapPixels2[x][y]=mapPixels[x-1][y];
- expansionOccurred=1;
- }else if(x-1>-1&&y-1>-1&&mapPixels[x-1][y-1]!=wasteland&&mapPixels[x-1][y-1]!=water){//225
- mapPixels2[x][y]=mapPixels[x-1][y-1];
- expansionOccurred=1;
- }else if(y-1>-1&&mapPixels[x][y-1]!=wasteland&&mapPixels[x][y-1]!=water){//270
- mapPixels2[x][y]=mapPixels[x][y-1];
- expansionOccurred=1;
- }else if(x+1<map0.width&&y-1>-1&&mapPixels[x+1][y-1]!=wasteland&&mapPixels[x+1][y-1]!=water){//315
- mapPixels2[x][y]=mapPixels[x+1][y-1];
- expansionOccurred=1;
- }
- }
- }
- }
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- mapPixels[x][y]=mapPixels2[x][y];
- }
- }
- }
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- if(mapPixels[x][y]==wasteland){
- mapPixels[x][y]=water;
- mapPixels2[x][y]=water;
- }
- map0.pixels[x+y*map0.width]=mapPixels[x][y];
- }
- }
- map0.updatePixels();
- map0.save("output/Expanded.png");
- }
- //3. First stage: Either one-pixel or two-pixel borders, depending on whether borderWidth is odd or even
- int borderWidthNow=0;//Tracks current border width (as opposed to desired border width, the borderWidth variable)
- color[][] mapPixels4=new color[map0.width][map0.height];//For the second border
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- mapPixels4[x][y]=mapPixels2[x][y];
- }
- }
- //One-pixel border: Checks east and north, then checks northeast
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- if(mapPixels[x][y]!=wasteland&&mapPixels[x][y]!=water&&mapPixels[x][y]!=uncolonized&&(wastelandBorders==1||mapPixels3[x][y]!=wasteland)){
- if(x+1<map0.width&&mapPixels[x+1][y]!=mapPixels[x][y]&&mapPixels[x+1][y]!=wasteland&&mapPixels[x+1][y]!=water&&mapPixels[x+1][y]!=uncolonized){
- mapPixels2[x][y]=color(0,0,0);
- }else if(y-1>-1&&mapPixels[x][y-1]!=mapPixels[x][y]&&mapPixels[x][y-1]!=wasteland&&mapPixels[x][y-1]!=water&&mapPixels[x][y-1]!=uncolonized){
- mapPixels2[x][y]=color(0,0,0);
- }
- }
- }
- }
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- if(mapPixels[x][y]!=wasteland&&mapPixels[x][y]!=water&&mapPixels[x][y]!=uncolonized&&(wastelandBorders==1||mapPixels3[x][y]!=wasteland)){
- if(x+1<map0.width&&y-1>-1&&mapPixels2[x+1][y]==color(0,0,0)&&mapPixels2[x+1][y-1]!=color(0,0,0)&&mapPixels2[x][y-1]==color(0,0,0)){
- mapPixels2[x][y]=color(0,0,0);
- }
- }
- }
- }
- borderWidthNow++;
- if(borderWidth%2==0){//Two-pixel addition: Checks west and south, then checks southwest
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- if(mapPixels[x][y]!=wasteland&&mapPixels[x][y]!=water&&mapPixels[x][y]!=uncolonized&&(wastelandBorders==1||mapPixels3[x][y]!=wasteland)){
- if(x-1>-1&&mapPixels[x-1][y]!=mapPixels[x][y]&&mapPixels[x-1][y]!=wasteland&&mapPixels[x-1][y]!=water&&mapPixels[x-1][y]!=uncolonized){
- mapPixels4[x][y]=color(0,0,0);
- }else if(y+1<map0.height&&mapPixels[x][y+1]!=mapPixels[x][y]&&mapPixels[x][y+1]!=wasteland&&mapPixels[x][y+1]!=water&&mapPixels[x][y+1]!=uncolonized){
- mapPixels4[x][y]=color(0,0,0);
- }
- }
- }
- }
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- if(mapPixels[x][y]!=wasteland&&mapPixels[x][y]!=water&&mapPixels[x][y]!=uncolonized&&(wastelandBorders==1||mapPixels3[x][y]!=wasteland)){
- if(x-1>-1&&y+1<map0.height&&mapPixels2[x-1][y]==color(0,0,0)&&mapPixels2[x-1][y+1]!=color(0,0,0)&&mapPixels2[x][y+1]==color(0,0,0)){
- mapPixels4[x][y]=color(0,0,0);
- }
- }
- }
- }
- borderWidthNow++;
- }
- //Copy second pixel of borders
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- if(mapPixels4[x][y]==color(0,0,0)){
- mapPixels2[x][y]=color(0,0,0);
- }
- }
- }
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- mapPixels[x][y]=mapPixels2[x][y];
- map0.pixels[x+y*map0.width]=mapPixels[x][y];
- }
- }
- //Second stage: Adding more pixels in layers of 2
- while(borderWidthNow<borderWidth){
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- if(mapPixels[x][y]!=wasteland&&mapPixels[x][y]!=water&&mapPixels[x][y]!=uncolonized&&(wastelandBorders==1||mapPixels3[x][y]!=wasteland)){
- if((x+1<map0.width&&mapPixels[x+1][y]==color(0,0,0))||(y+1<map0.height&&mapPixels[x][y+1]==color(0,0,0))||(x-1>-1&&mapPixels[x-1][y]==color(0,0,0))||(y-1>-1&&mapPixels[x][y-1]==color(0,0,0))){
- mapPixels2[x][y]=color(0,0,0);
- }
- }
- }
- }
- for(int x=0;x<map0.width;x++){
- for(int y=0;y<map0.height;y++){
- mapPixels[x][y]=mapPixels2[x][y];
- map0.pixels[x+y*map0.width]=mapPixels[x][y];
- }
- }
- borderWidthNow+=2;
- }
- map0.updatePixels();
- map0.save(savePath("output/Bordered.png"));
- exit();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement