diff --git a/dungeon-plot/Pipfile b/dungeon-plot/Pipfile new file mode 100644 index 0000000..9cbfc61 --- /dev/null +++ b/dungeon-plot/Pipfile @@ -0,0 +1,15 @@ +[[source]] +url = "https://pypi.org/simple" +verify_ssl = true +name = "pypi" + +[packages] +perlin-noise = "*" +opencv-python = "*" +pillow = "*" + +[dev-packages] + +[requires] +python_version = "3.11" +python_full_version = "3.11.11" diff --git a/dungeon-plot/Pipfile.lock b/dungeon-plot/Pipfile.lock new file mode 100644 index 0000000..dfbdc2b --- /dev/null +++ b/dungeon-plot/Pipfile.lock @@ -0,0 +1,183 @@ +{ + "_meta": { + "hash": { + "sha256": "2553c9eba8cb970f0e6947604776d0252df7123df82d43616277a066fc0ee1cd" + }, + "pipfile-spec": 6, + "requires": { + "python_full_version": "3.11.11", + "python_version": "3.11" + }, + "sources": [ + { + "name": "pypi", + "url": "https://pypi.org/simple", + "verify_ssl": true + } + ] + }, + "default": { + "numpy": { + "hashes": [ + "sha256:05c076d531e9998e7e694c36e8b349969c56eadd2cdcd07242958489d79a7286", + "sha256:0d54974f9cf14acf49c60f0f7f4084b6579d24d439453d5fc5805d46a165b542", + "sha256:11c43995255eb4127115956495f43e9343736edb7fcdb0d973defd9de14cd84f", + "sha256:188dcbca89834cc2e14eb2f106c96d6d46f200fe0200310fc29089657379c58d", + "sha256:1974afec0b479e50438fc3648974268f972e2d908ddb6d7fb634598cdb8260a0", + "sha256:1cf4e5c6a278d620dee9ddeb487dc6a860f9b199eadeecc567f777daace1e9e7", + "sha256:207a2b8441cc8b6a2a78c9ddc64d00d20c303d79fba08c577752f080c4007ee3", + "sha256:218f061d2faa73621fa23d6359442b0fc658d5b9a70801373625d958259eaca3", + "sha256:2aad3c17ed2ff455b8eaafe06bcdae0062a1db77cb99f4b9cbb5f4ecb13c5146", + "sha256:2fa8fa7697ad1646b5c93de1719965844e004fcad23c91228aca1cf0800044a1", + "sha256:31504f970f563d99f71a3512d0c01a645b692b12a63630d6aafa0939e52361e6", + "sha256:3387dd7232804b341165cedcb90694565a6015433ee076c6754775e85d86f1fc", + "sha256:4ba5054787e89c59c593a4169830ab362ac2bee8a969249dc56e5d7d20ff8df9", + "sha256:4f92084defa704deadd4e0a5ab1dc52d8ac9e8a8ef617f3fbb853e79b0ea3592", + "sha256:65ef3468b53269eb5fdb3a5c09508c032b793da03251d5f8722b1194f1790c00", + "sha256:6f527d8fdb0286fd2fd97a2a96c6be17ba4232da346931d967a0630050dfd298", + "sha256:7051ee569db5fbac144335e0f3b9c2337e0c8d5c9fee015f259a5bd70772b7e8", + "sha256:7716e4a9b7af82c06a2543c53ca476fa0b57e4d760481273e09da04b74ee6ee2", + "sha256:79bd5f0a02aa16808fcbc79a9a376a147cc1045f7dfe44c6e7d53fa8b8a79392", + "sha256:7a4e84a6283b36632e2a5b56e121961f6542ab886bc9e12f8f9818b3c266bfbb", + "sha256:8120575cb4882318c791f839a4fd66161a6fa46f3f0a5e613071aae35b5dd8f8", + "sha256:81413336ef121a6ba746892fad881a83351ee3e1e4011f52e97fba79233611fd", + "sha256:8146f3550d627252269ac42ae660281d673eb6f8b32f113538e0cc2a9aed42b9", + "sha256:879cf3a9a2b53a4672a168c21375166171bc3932b7e21f622201811c43cdd3b0", + "sha256:892c10d6a73e0f14935c31229e03325a7b3093fafd6ce0af704be7f894d95687", + "sha256:92bda934a791c01d6d9d8e038363c50918ef7c40601552a58ac84c9613a665bc", + "sha256:9ba03692a45d3eef66559efe1d1096c4b9b75c0986b5dff5530c378fb8331d4f", + "sha256:9eeea959168ea555e556b8188da5fa7831e21d91ce031e95ce23747b7609f8a4", + "sha256:a0258ad1f44f138b791327961caedffbf9612bfa504ab9597157806faa95194a", + "sha256:a761ba0fa886a7bb33c6c8f6f20213735cb19642c580a931c625ee377ee8bd39", + "sha256:a7b9084668aa0f64e64bd00d27ba5146ef1c3a8835f3bd912e7a9e01326804c4", + "sha256:a84eda42bd12edc36eb5b53bbcc9b406820d3353f1994b6cfe453a33ff101775", + "sha256:ab2939cd5bec30a7430cbdb2287b63151b77cf9624de0532d629c9a1c59b1d5c", + "sha256:ac0280f1ba4a4bfff363a99a6aceed4f8e123f8a9b234c89140f5e894e452ecd", + "sha256:adf8c1d66f432ce577d0197dceaac2ac00c0759f573f28516246351c58a85020", + "sha256:b4adfbbc64014976d2f91084915ca4e626fbf2057fb81af209c1a6d776d23e3d", + "sha256:bb649f8b207ab07caebba230d851b579a3c8711a851d29efe15008e31bb4de24", + "sha256:bce43e386c16898b91e162e5baaad90c4b06f9dcbe36282490032cec98dc8ae7", + "sha256:bd3ad3b0a40e713fc68f99ecfd07124195333f1e689387c180813f0e94309d6f", + "sha256:c3f7ac96b16955634e223b579a3e5798df59007ca43e8d451a0e6a50f6bfdfba", + "sha256:cf28633d64294969c019c6df4ff37f5698e8326db68cc2b66576a51fad634880", + "sha256:d0f35b19894a9e08639fd60a1ec1978cb7f5f7f1eace62f38dd36be8aecdef4d", + "sha256:db1f1c22173ac1c58db249ae48aa7ead29f534b9a948bc56828337aa84a32ed6", + "sha256:dbe512c511956b893d2dacd007d955a3f03d555ae05cfa3ff1c1ff6df8851854", + "sha256:df2f57871a96bbc1b69733cd4c51dc33bea66146b8c63cacbfed73eec0883017", + "sha256:e2f085ce2e813a50dfd0e01fbfc0c12bbe5d2063d99f8b29da30e544fb6483b8", + "sha256:e642d86b8f956098b564a45e6f6ce68a22c2c97a04f5acd3f221f57b8cb850ae", + "sha256:e9e0a277bb2eb5d8a7407e14688b85fd8ad628ee4e0c7930415687b6564207a4", + "sha256:ea2bb7e2ae9e37d96835b3576a4fa4b3a97592fbea8ef7c3587078b0068b8f09", + "sha256:ee4d528022f4c5ff67332469e10efe06a267e32f4067dc76bb7e2cddf3cd25ff", + "sha256:f05d4198c1bacc9124018109c5fba2f3201dbe7ab6e92ff100494f236209c960", + "sha256:f34dc300df798742b3d06515aa2a0aee20941c13579d7a2f2e10af01ae4901ee", + "sha256:f4162988a360a29af158aeb4a2f4f09ffed6a969c9776f8f3bdee9b06a8ab7e5", + "sha256:f486038e44caa08dbd97275a9a35a283a8f1d2f0ee60ac260a1790e76660833c", + "sha256:f7de08cbe5551911886d1ab60de58448c6df0f67d9feb7d1fb21e9875ef95e91" + ], + "markers": "python_version >= '3.10'", + "version": "==2.2.4" + }, + "opencv-python": { + "hashes": [ + "sha256:03d60ccae62304860d232272e4a4fda93c39d595780cb40b161b310244b736a4", + "sha256:085ad9b77c18853ea66283e98affefe2de8cc4c1f43eda4c100cf9b2721142ec", + "sha256:1b92ae2c8852208817e6776ba1ea0d6b1e0a1b5431e971a2a0ddd2a8cc398202", + "sha256:432f67c223f1dc2824f5e73cdfcd9db0efc8710647d4e813012195dc9122a52a", + "sha256:6b02611523803495003bd87362db3e1d2a0454a6a63025dc6658a9830570aa0d", + "sha256:810549cb2a4aedaa84ad9a1c92fbfdfc14090e2749cedf2c1589ad8359aa169b", + "sha256:9d05ef13d23fe97f575153558653e2d6e87103995d54e6a35db3f282fe1f9c66" + ], + "index": "pypi", + "markers": "python_version >= '3.6'", + "version": "==4.11.0.86" + }, + "perlin-noise": { + "hashes": [ + "sha256:09f274c8da38f5a2a48b1626032a1b7738990df758a3bc7549ff3464869c6ca4", + "sha256:0e0f074743336fbe9cf2cdbdeb74c75d43780a8b3cbc3415859cd396ab4da177" + ], + "index": "pypi", + "version": "==1.13" + }, + "pillow": { + "hashes": [ + "sha256:015c6e863faa4779251436db398ae75051469f7c903b043a48f078e437656f83", + "sha256:0a2f91f8a8b367e7a57c6e91cd25af510168091fb89ec5146003e424e1558a96", + "sha256:11633d58b6ee5733bde153a8dafd25e505ea3d32e261accd388827ee987baf65", + "sha256:2062ffb1d36544d42fcaa277b069c88b01bb7298f4efa06731a7fd6cc290b81a", + "sha256:31eba6bbdd27dde97b0174ddf0297d7a9c3a507a8a1480e1e60ef914fe23d352", + "sha256:3362c6ca227e65c54bf71a5f88b3d4565ff1bcbc63ae72c34b07bbb1cc59a43f", + "sha256:368da70808b36d73b4b390a8ffac11069f8a5c85f29eff1f1b01bcf3ef5b2a20", + "sha256:36ba10b9cb413e7c7dfa3e189aba252deee0602c86c309799da5a74009ac7a1c", + "sha256:3764d53e09cdedd91bee65c2527815d315c6b90d7b8b79759cc48d7bf5d4f114", + "sha256:3a5fe20a7b66e8135d7fd617b13272626a28278d0e578c98720d9ba4b2439d49", + "sha256:3cdcdb0b896e981678eee140d882b70092dac83ac1cdf6b3a60e2216a73f2b91", + "sha256:4637b88343166249fe8aa94e7c4a62a180c4b3898283bb5d3d2fd5fe10d8e4e0", + "sha256:4db853948ce4e718f2fc775b75c37ba2efb6aaea41a1a5fc57f0af59eee774b2", + "sha256:4dd43a78897793f60766563969442020e90eb7847463eca901e41ba186a7d4a5", + "sha256:54251ef02a2309b5eec99d151ebf5c9904b77976c8abdcbce7891ed22df53884", + "sha256:54ce1c9a16a9561b6d6d8cb30089ab1e5eb66918cb47d457bd996ef34182922e", + "sha256:593c5fd6be85da83656b93ffcccc2312d2d149d251e98588b14fbc288fd8909c", + "sha256:5bb94705aea800051a743aa4874bb1397d4695fb0583ba5e425ee0328757f196", + "sha256:67cd427c68926108778a9005f2a04adbd5e67c442ed21d95389fe1d595458756", + "sha256:70ca5ef3b3b1c4a0812b5c63c57c23b63e53bc38e758b37a951e5bc466449861", + "sha256:73ddde795ee9b06257dac5ad42fcb07f3b9b813f8c1f7f870f402f4dc54b5269", + "sha256:758e9d4ef15d3560214cddbc97b8ef3ef86ce04d62ddac17ad39ba87e89bd3b1", + "sha256:7d33d2fae0e8b170b6a6c57400e077412240f6f5bb2a342cf1ee512a787942bb", + "sha256:7fdadc077553621911f27ce206ffcbec7d3f8d7b50e0da39f10997e8e2bb7f6a", + "sha256:8000376f139d4d38d6851eb149b321a52bb8893a88dae8ee7d95840431977081", + "sha256:837060a8599b8f5d402e97197d4924f05a2e0d68756998345c829c33186217b1", + "sha256:89dbdb3e6e9594d512780a5a1c42801879628b38e3efc7038094430844e271d8", + "sha256:8c730dc3a83e5ac137fbc92dfcfe1511ce3b2b5d7578315b63dbbb76f7f51d90", + "sha256:8e275ee4cb11c262bd108ab2081f750db2a1c0b8c12c1897f27b160c8bd57bbc", + "sha256:9044b5e4f7083f209c4e35aa5dd54b1dd5b112b108648f5c902ad586d4f945c5", + "sha256:93a18841d09bcdd774dcdc308e4537e1f867b3dec059c131fde0327899734aa1", + "sha256:9409c080586d1f683df3f184f20e36fb647f2e0bc3988094d4fd8c9f4eb1b3b3", + "sha256:96f82000e12f23e4f29346e42702b6ed9a2f2fea34a740dd5ffffcc8c539eb35", + "sha256:9aa9aeddeed452b2f616ff5507459e7bab436916ccb10961c4a382cd3e03f47f", + "sha256:9ee85f0696a17dd28fbcfceb59f9510aa71934b483d1f5601d1030c3c8304f3c", + "sha256:a07dba04c5e22824816b2615ad7a7484432d7f540e6fa86af60d2de57b0fcee2", + "sha256:a3cd561ded2cf2bbae44d4605837221b987c216cff94f49dfeed63488bb228d2", + "sha256:a697cd8ba0383bba3d2d3ada02b34ed268cb548b369943cd349007730c92bddf", + "sha256:a76da0a31da6fcae4210aa94fd779c65c75786bc9af06289cd1c184451ef7a65", + "sha256:a85b653980faad27e88b141348707ceeef8a1186f75ecc600c395dcac19f385b", + "sha256:a8d65b38173085f24bc07f8b6c505cbb7418009fa1a1fcb111b1f4961814a442", + "sha256:aa8dd43daa836b9a8128dbe7d923423e5ad86f50a7a14dc688194b7be5c0dea2", + "sha256:ab8a209b8485d3db694fa97a896d96dd6533d63c22829043fd9de627060beade", + "sha256:abc56501c3fd148d60659aae0af6ddc149660469082859fa7b066a298bde9482", + "sha256:ad5db5781c774ab9a9b2c4302bbf0c1014960a0a7be63278d13ae6fdf88126fe", + "sha256:ae98e14432d458fc3de11a77ccb3ae65ddce70f730e7c76140653048c71bfcbc", + "sha256:b20be51b37a75cc54c2c55def3fa2c65bb94ba859dde241cd0a4fd302de5ae0a", + "sha256:b523466b1a31d0dcef7c5be1f20b942919b62fd6e9a9be199d035509cbefc0ec", + "sha256:b5d658fbd9f0d6eea113aea286b21d3cd4d3fd978157cbf2447a6035916506d3", + "sha256:b6123aa4a59d75f06e9dd3dac5bf8bc9aa383121bb3dd9a7a612e05eabc9961a", + "sha256:bd165131fd51697e22421d0e467997ad31621b74bfc0b75956608cb2906dda07", + "sha256:bf902d7413c82a1bfa08b06a070876132a5ae6b2388e2712aab3a7cbc02205c6", + "sha256:c12fc111ef090845de2bb15009372175d76ac99969bdf31e2ce9b42e4b8cd88f", + "sha256:c1eec9d950b6fe688edee07138993e54ee4ae634c51443cfb7c1e7613322718e", + "sha256:c640e5a06869c75994624551f45e5506e4256562ead981cce820d5ab39ae2192", + "sha256:cc1331b6d5a6e144aeb5e626f4375f5b7ae9934ba620c0ac6b3e43d5e683a0f0", + "sha256:cfd5cd998c2e36a862d0e27b2df63237e67273f2fc78f47445b14e73a810e7e6", + "sha256:d3d8da4a631471dfaf94c10c85f5277b1f8e42ac42bade1ac67da4b4a7359b73", + "sha256:d44ff19eea13ae4acdaaab0179fa68c0c6f2f45d66a4d8ec1eda7d6cecbcc15f", + "sha256:dd0052e9db3474df30433f83a71b9b23bd9e4ef1de13d92df21a52c0303b8ab6", + "sha256:dd0e081319328928531df7a0e63621caf67652c8464303fd102141b785ef9547", + "sha256:dda60aa465b861324e65a78c9f5cf0f4bc713e4309f83bc387be158b077963d9", + "sha256:e06695e0326d05b06833b40b7ef477e475d0b1ba3a6d27da1bb48c23209bf457", + "sha256:e1abe69aca89514737465752b4bcaf8016de61b3be1397a8fc260ba33321b3a8", + "sha256:e267b0ed063341f3e60acd25c05200df4193e15a4a5807075cd71225a2386e26", + "sha256:e5449ca63da169a2e6068dd0e2fcc8d91f9558aba89ff6d02121ca8ab11e79e5", + "sha256:e63e4e5081de46517099dc30abe418122f54531a6ae2ebc8680bcd7096860eab", + "sha256:f189805c8be5ca5add39e6f899e6ce2ed824e65fb45f3c28cb2841911da19070", + "sha256:f7955ecf5609dee9442cbface754f2c6e541d9e6eda87fad7f7a989b0bdb9d71", + "sha256:f86d3a7a9af5d826744fabf4afd15b9dfef44fe69a98541f666f66fbb8d3fef9", + "sha256:fbd43429d0d7ed6533b25fc993861b8fd512c42d04514a0dd6337fb3ccf22761" + ], + "index": "pypi", + "markers": "python_version >= '3.9'", + "version": "==11.1.0" + } + }, + "develop": {} +} diff --git a/dungeon-plot/dungeon.py b/dungeon-plot/dungeon.py new file mode 100644 index 0000000..4502b87 --- /dev/null +++ b/dungeon-plot/dungeon.py @@ -0,0 +1,102 @@ +import matplotlib.pyplot as plt +from matplotlib import colors +import numpy as np +from perlin_noise import PerlinNoise +import cv2 as cv +import os +from PIL import Image +import sys + +data = np.random.rand(16, 16) + + +def generate_base_map(filename): + print("generating base map...") + + cmap = colors.ListedColormap(['white', 'black']) + bounds = [0, .5, 1] + norm = colors.BoundaryNorm(bounds, cmap.N) + + #dpi=96 + #size=512 + #fig, ax = plt.subplots(1, 1, figsize=(size/dpi, size/dpi)) + fig, ax = plt.subplots() + ax.imshow(data, cmap=cmap, norm=norm) + + plt.axis('off') + + plt.savefig(filename, bbox_inches='tight', pad_inches=0) + im = Image.open(filename) + out = im.resize((512,512)) + out.save(filename) + #plt.savefig('../marshroom/dungeon/dungeon.png', bbox_inches='tight', pad_inches=0, dpi=dpi) + + +def generate_perlin(filename): + print("generating perlin noise...") + + noise = PerlinNoise(octaves=10, seed=1) + xpix, ypix = 512, 512 + pic = [[noise([i/xpix, j/ypix]) for j in range(xpix)] for i in range(ypix)] + + plt.imshow(pic, cmap='gray') + plt.savefig(filename, bbox_inches='tight', pad_inches=0) + im = Image.open(filename) + out = im.resize((512,512)) + out.save(filename) + + +def generate_loot_probability_map(filename, noise_filename, mask_filename): + print("generating loot probabilities...") + + #noise = cv.imread(noise_filename) + mask = cv.imread(mask_filename, 0) + mask = cv.bitwise_not(mask) + + kernel_size = 32 + kernel = np.ones((kernel_size, kernel_size), np.uint8) + eroded = cv.erode(mask, kernel) + + # use quarter-circle kernels to build up shadows in 90 degree corners + centres = [ + (-1, -1), + (-1, kernel_size+1), + (kernel_size+1, -1), + (kernel_size+1, kernel_size+1)] + + joined = mask.copy() + + for centre in centres: + circle_kernel = np.zeros((kernel_size, kernel_size), np.uint8) + cv.circle(circle_kernel, centre, kernel_size, 255, -1) + dilated = cv.dilate(eroded, circle_kernel, iterations=1) + joined[dilated == 0] = 0 + + # we want white in the corners and black on floors and in wall so we need to invert the colours + inverted = cv.bitwise_not(joined) + + # inverting it turns the shadows white, but now the inside of the walls are also white, where we want them to be black. + # in the base map the inside of walls is white. + # we therefore want to set pixels in the output to zero where the base map is white + invmask = cv.bitwise_not(mask) + inverted -= invmask + + # we're left with some narrow artifacts which we can erode away + erodedinv = cv.erode(inverted, np.ones((3,3),np.uint8)) + + # modulate with noise? + + cv.imwrite(filename, erodedinv) + + +noise = 'perlin.png' +map = 'map.png' +loot = 'loot.png' + +#generate_perlin(noise) +#generate_base_map(map) +generate_loot_probability_map(loot, noise, map) + + + + diff --git a/dungeon-plot/dungeon.sh b/dungeon-plot/dungeon.sh new file mode 100755 index 0000000..f2b3415 --- /dev/null +++ b/dungeon-plot/dungeon.sh @@ -0,0 +1,13 @@ +infiles="map.png heat.png" +outdir="../marshroom/dungeon/" + +pipenv run python dungeon.py + +for f in $infiles +do + #magick $f -resize 512x512 $f + echo $f +done + +#cp $infile $outfile +sxiv *.png