Created
November 19, 2014 22:42
-
-
Save stewsters/a858d8e0994f975fecec to your computer and use it in GitHub Desktop.
Random asteroid generation
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
public RandomAsteroidBuilder makeBall(float radius) { | |
int x2 = width / 2; | |
int y2 = height / 2; | |
int z2 = depth / 2; | |
float radiusShare = 8; | |
float randomShare = 2; | |
for (int x = 0; x < width; x++) { | |
for (int y = 0; y < height; y++) { | |
for (int z = 0; z < depth; z++) { | |
float radiusComponent = (float) Math.sqrt(Math.pow(x2 - x, 2) + Math.pow(y2 - y, 2) + Math.pow(z2 - z, 2)); | |
float noiseComponent = ( | |
SimplexNoise3D.eval(x / 10f, y / 10f, z / 10f) + | |
SimplexNoise3D.eval(x / 100f, y / 100f, z / 100f)) / 2.0f; | |
float density = ((radiusShare * radius / radiusComponent) + randomShare * (noiseComponent - 0.5f)) / (radiusShare + randomShare); | |
TileType type; | |
if (density < 0.5) { | |
type = Textures.tileTypes.get("void"); | |
} else if (density < 0.6) { | |
type = Textures.tileTypes.get("silicon rock"); | |
} else if (density < 1.0) { | |
type = Textures.tileTypes.get("carbon rock"); | |
} else { | |
if (SimplexNoise3D.eval(x / 4f, y / 4f, z / 4f) < 0.6) { | |
type = Textures.tileTypes.get("common ore"); | |
} else { | |
type = Textures.tileTypes.get("precious ore"); | |
} | |
} | |
tiles[x][y][z] = type; | |
} | |
} | |
} | |
return this; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment