2018-10-20 09:59:53 +02:00
|
|
|
{
|
|
|
|
"cells": [
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"# Perlin World Generator Test\n",
|
2018-10-24 20:59:22 +02:00
|
|
|
"---\n",
|
|
|
|
"this notebook tests the Perlin world generator"
|
2018-10-20 09:59:53 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 1,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"import sys\n",
|
|
|
|
"sys.path.append(\"../ServerCore\")"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 2,
|
|
|
|
"metadata": {},
|
2018-11-15 10:38:38 +01:00
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"name": "stdout",
|
|
|
|
"output_type": "stream",
|
|
|
|
"text": [
|
|
|
|
"Populating the interactive namespace from numpy and matplotlib\n"
|
|
|
|
]
|
|
|
|
}
|
|
|
|
],
|
2018-10-20 09:59:53 +02:00
|
|
|
"source": [
|
2018-11-15 10:38:38 +01:00
|
|
|
"%pylab ipympl\n",
|
2018-10-23 22:57:55 +02:00
|
|
|
"\n",
|
2018-10-20 09:59:53 +02:00
|
|
|
"import matplotlib.image as mpimg\n",
|
|
|
|
"import scipy.ndimage as ndimage\n",
|
|
|
|
"import matplotlib.pyplot as plt\n",
|
2018-10-23 23:29:26 +02:00
|
|
|
"\n",
|
2018-10-20 09:59:53 +02:00
|
|
|
"import numpy as np\n",
|
|
|
|
"\n",
|
|
|
|
"from WorldManager import WorldManager\n",
|
|
|
|
"from Chunk import Chunk"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"* variables:"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 3,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2018-10-23 23:29:26 +02:00
|
|
|
"n_chunks = 3\n",
|
2018-10-20 09:59:53 +02:00
|
|
|
"raw_noise_cell_size = 16\n",
|
|
|
|
"raw_noise_chunk_size = 4\n",
|
|
|
|
"world_seed = 42"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"* create world manager"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 4,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"wm = WorldManager(raw_noise_cell_size=raw_noise_cell_size, raw_noise_chunk_size=raw_noise_chunk_size, world_seed=world_seed)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"* create world's highmap"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 5,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"c = Chunk.CHUNK_SIDELENGTH\n",
|
|
|
|
"\n",
|
|
|
|
"height_map = np.zeros(shape=(n_chunks * c, n_chunks * c), dtype=float)\n",
|
|
|
|
"\n",
|
|
|
|
"for i in range(n_chunks):\n",
|
|
|
|
" for j in range(n_chunks):\n",
|
|
|
|
" height_map[i * c:(i+1)* c, j*c:(j+1)*c] = wm.getPerlinMap(i,j)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"* plot height map"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 6,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"data": {
|
2018-11-15 10:38:38 +01:00
|
|
|
"application/vnd.jupyter.widget-view+json": {
|
2018-11-27 19:04:35 +01:00
|
|
|
"model_id": "23dd04daba304f2d9668d861184e7153",
|
2018-11-15 10:38:38 +01:00
|
|
|
"version_major": 2,
|
|
|
|
"version_minor": 0
|
|
|
|
},
|
2018-10-20 09:59:53 +02:00
|
|
|
"text/plain": [
|
2018-11-15 10:38:38 +01:00
|
|
|
"FigureCanvasNbAgg()"
|
2018-10-20 09:59:53 +02:00
|
|
|
]
|
|
|
|
},
|
2018-11-15 10:38:38 +01:00
|
|
|
"metadata": {},
|
2018-10-20 09:59:53 +02:00
|
|
|
"output_type": "display_data"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
|
|
|
"fig, ax = plt.subplots()\n",
|
|
|
|
"\n",
|
|
|
|
"ax.imshow(height_map, cmap='binary')\n",
|
|
|
|
"ax.set_title(\"stupid interpolated perlin noise map\")\n",
|
|
|
|
"plt.show()"
|
|
|
|
]
|
|
|
|
},
|
2018-10-23 22:57:55 +02:00
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"* create chunks and fill them with data"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 7,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"for x in range(n_chunks):\n",
|
|
|
|
" for y in range(2):\n",
|
|
|
|
" for z in range(n_chunks):\n",
|
|
|
|
" wm.createEmptyChunk(x,y,z)\n",
|
|
|
|
" wm.applyPerlinToChunk(x,y,z)\n",
|
|
|
|
" "
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"* concatenate to one big array (just for plotting)"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 8,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"world = np.zeros(shape=(n_chunks * c, 2*c, n_chunks*c), dtype=int)\n",
|
|
|
|
"\n",
|
|
|
|
"for x in range(n_chunks):\n",
|
|
|
|
" for y in range(2):\n",
|
|
|
|
" for z in range(n_chunks):\n",
|
|
|
|
" world[x*c:(x+1)*c, y*c:(y+1)*c, z*c:(z+1)*c] = wm.chunks[x][y][z].block_data"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "markdown",
|
|
|
|
"metadata": {},
|
|
|
|
"source": [
|
|
|
|
"* and plot it"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 9,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
2018-10-23 23:29:26 +02:00
|
|
|
"from mpl_toolkits.mplot3d import Axes3D\n"
|
2018-10-23 22:57:55 +02:00
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 10,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [],
|
|
|
|
"source": [
|
|
|
|
"colors = np.zeros(shape=(n_chunks * c, 2*c, n_chunks*c,3))\n",
|
|
|
|
"for x,y,z in np.ndindex(world.shape):\n",
|
|
|
|
" i = y/(c)\n",
|
|
|
|
" colors[x,y,z,:] = [0,i,1-i]"
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"cell_type": "code",
|
|
|
|
"execution_count": 11,
|
|
|
|
"metadata": {},
|
|
|
|
"outputs": [
|
|
|
|
{
|
|
|
|
"data": {
|
2018-11-15 10:38:38 +01:00
|
|
|
"application/vnd.jupyter.widget-view+json": {
|
2018-11-27 19:04:35 +01:00
|
|
|
"model_id": "3010f3d5167449b196314981a687108b",
|
2018-11-15 10:38:38 +01:00
|
|
|
"version_major": 2,
|
|
|
|
"version_minor": 0
|
|
|
|
},
|
2018-10-23 22:57:55 +02:00
|
|
|
"text/plain": [
|
2018-11-15 10:38:38 +01:00
|
|
|
"FigureCanvasNbAgg()"
|
2018-10-23 22:57:55 +02:00
|
|
|
]
|
|
|
|
},
|
2018-11-15 10:38:38 +01:00
|
|
|
"metadata": {},
|
2018-10-23 22:57:55 +02:00
|
|
|
"output_type": "display_data"
|
|
|
|
}
|
|
|
|
],
|
|
|
|
"source": [
|
2018-11-15 10:38:38 +01:00
|
|
|
"\n",
|
|
|
|
"fig2 = plt.figure()\n",
|
2018-10-23 23:29:26 +02:00
|
|
|
"ax2 = fig2.gca(projection='3d')\n",
|
2018-10-23 22:57:55 +02:00
|
|
|
"\n",
|
2018-10-23 23:29:26 +02:00
|
|
|
"p = ax2.voxels(np.rollaxis(world,2), facecolors=np.rollaxis(colors,2))"
|
2018-10-23 22:57:55 +02:00
|
|
|
]
|
2018-10-20 09:59:53 +02:00
|
|
|
}
|
|
|
|
],
|
|
|
|
"metadata": {
|
|
|
|
"kernelspec": {
|
|
|
|
"display_name": "Python 3",
|
|
|
|
"language": "python",
|
|
|
|
"name": "python3"
|
|
|
|
},
|
|
|
|
"language_info": {
|
|
|
|
"codemirror_mode": {
|
|
|
|
"name": "ipython",
|
|
|
|
"version": 3
|
|
|
|
},
|
|
|
|
"file_extension": ".py",
|
|
|
|
"mimetype": "text/x-python",
|
|
|
|
"name": "python",
|
|
|
|
"nbconvert_exporter": "python",
|
|
|
|
"pygments_lexer": "ipython3",
|
2018-11-27 19:04:35 +01:00
|
|
|
"version": "3.6.7"
|
2018-10-20 09:59:53 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
"nbformat": 4,
|
|
|
|
"nbformat_minor": 2
|
|
|
|
}
|