Created
February 16, 2018 15:59
-
-
Save ItsMeThom-zz/53fd34264449f33f04a36a7084080084 to your computer and use it in GitHub Desktop.
Prototype code to generate a portion of a radial gradient (As opposed to an entire gradient) for use in masking a heighmap to be island shaped
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import math | |
| import time | |
| chunk_size = 128; | |
| map_width_in_chunks = 128 | |
| center_chunk = [0,0] | |
| coordinates = [0,0] | |
| center_map = map_width_in_chunks / 2 | |
| centerX = (map_width_in_chunks * chunk_size) / 2 | |
| centerZ = centerX | |
| #wholemap = [[1.0 for _ in range(0,map_width_in_chunks * chunk_size)] for _ in range(0,map_width_in_chunks * chunk_size)] | |
| #standard gradient function | |
| #for x in range(0, map_width_in_chunks * chunk_size): | |
| # for z in range(0, map_width_in_chunks * chunk_size): | |
| # distanceX = (centerX - x) * (centerX - x) | |
| # distanceZ = (centerZ - z) * (centerZ - z) | |
| # distanceToCenter = math.sqrt(distanceX + distanceZ) | |
| # wholemap[x][z] = distanceToCenter | |
| #for row in wholemap:# | |
| # | |
| # rowstring = "" | |
| # for a in row: | |
| # item = "{:10.2f}".format(a) | |
| # rowstring += item | |
| # print(rowstring) | |
| # print("") | |
| print("Now trying to get chunk gradient without computing entire gradient") | |
| startChunkX = chunk_size * coordinates[0] | |
| startChunkZ = chunk_size * coordinates[1] | |
| t0 = time.time(); | |
| chunkmap = [[1.0 for _ in range(chunk_size)] for _ in range(0, chunk_size)] | |
| cX = 0 | |
| cZ = 0 | |
| endX = startChunkX + chunk_size | |
| endZ = startChunkZ + chunk_size | |
| for x in range(startChunkX, endX): | |
| cZ = 0 | |
| for z in range(startChunkZ, endZ): | |
| distanceX = (centerX - x) * (centerX - x) | |
| distanceZ = (centerZ - z) * (centerZ - z) | |
| distanceToCenter = math.sqrt(distanceX + distanceZ) | |
| chunkmap[cX][cZ] = distanceToCenter | |
| cZ += 1 | |
| cX += 1 | |
| t1 = time.time(); | |
| print("CHUNK: [{0},{1}]".format(coordinates[0], coordinates[1])) | |
| for row in chunkmap: | |
| rowstring = "" | |
| for a in row: | |
| item = "{:10.2f}".format(a) | |
| rowstring += item | |
| print(rowstring) | |
| print("") | |
| print("Total time to generate: {0}".format(t1 - t0)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment