/// <summary> /// generates height for a given terrain cell /// </summary> /// <param name="terrain"></param> /// <param name="args"></param> private static void heightBuilder(Terrain terrain, params object[] args) { int x = (int)args[0]; int y = (int)args[1]; int dx = (int)args[2]; int dy = (int)args[3]; float z = (float)args[4]; w_ProgressMessage = (int)((float)((float)(x * dx + y) / (float)(dx * dx + dy)) * 100f) + "%"; //set height float height = (float)w_Perlin.GetValue((double)((double)x / dx), (double)((double)y / dy), (double)z); terrain.Height = height > 1f ? 1f : height; //set base to land terrain.TerrainType = TerrainType_Old.BASE_LAND; terrain.Moisture = MOISTURE_LAND; if (terrain.Height <= HEIGHT_OCEAN) { terrain.TerrainType = TerrainType_Old.BASE_OCEAN; terrain.Moisture = MOISTURE_OCEAN; } if (terrain.Height >= HEIGHT_MOUNTAIN) { terrain.TerrainType = TerrainType_Old.BASE_MOUNTAIN; terrain.Moisture = MOISTURE_MOUNTAIN; } }
bool SpawnTree(Block _block, int _sparsity) { int xBlockOffset = _block.Row + XOffset * Length , zBlockOffset = _block.Col + ZOffset * Length; var maxNoise = double.MinValue; for (int x = xBlockOffset - _sparsity; x <= xBlockOffset; ++x) { for (int z = zBlockOffset - _sparsity; z <= zBlockOffset; ++z) { var currentNoise = elevationNoiseGen.GetValue(x + XOffset * Length, 0.1, z + ZOffset * Length); if (maxNoise < currentNoise) { maxNoise = currentNoise; } } } if (maxNoise == elevationNoiseGen.GetValue(xBlockOffset + XOffset * Length, 0.1, zBlockOffset + ZOffset * Length)) { var treeObj = Instantiate(ChunkLoader.Instance.prefabTree); treeObj.transform.position = _block.transform.position + Vector3.up * (_block.transform.localScale[1] / 2 + transform.localScale[1] / 2); treeObj.transform.SetParent(transform); _block.NonTraversable = true; return(true); } return(false); }
// Libnoise Perlin void GenerateMeshL() { mesh = gameObject.GetComponent <MeshFilter>().mesh; renderer = gameObject.GetComponent <MeshRenderer>(); renderer.material = new Material(Shader.Find("DAB/Vertex Detail Specular")); Vector3[] verts = mesh.vertices; perlin = new Perlin(); perlin.Seed = (int)System.DateTime.Now.Ticks; perlin.Lacunarity = selectedClimate.maxLacunarity; perlin.Persistence = selectedClimate.maxPersistance; perlin.OctaveCount = selectedClimate.maxOctaves; perlin.Frequency = selectedClimate.maxFrequency; for (int i = 0; i < verts.Length; i++) { verts[i].x += (float)perlin.GetValue(verts[i]) * 0.2f; //(Perlin.Fbm(verts[i], 2) * 0.6f); verts[i].y += (float)perlin.GetValue(verts[i]) * 0.2f; //(Perlin.Fbm(verts[i], 2) * 0.6f); verts[i].z += (float)perlin.GetValue(verts[i]) * 0.2f; //(Perlin.Fbm(verts[i], 2) * 0.6f); } mesh.vertices = verts; mesh.RecalculateBounds(); gameObject.AddComponent <MeshCollider>(); }
// Generate a generally boring metallic-like texture (ships and stations use this) public static SS_Texture GenerateBaseTexture(int seed, int textureWidth, int textureHeight, int detail) { SS_Texture tmpTexture = new SS_Texture(textureWidth, textureHeight, Color.clear); Perlin noise = new Perlin(0.005, 2, 0.5, 6, seed, QualityMode.Low); int offsetX = tmpTexture.Width / detail; int offsetY = tmpTexture.Height / detail; for (int y = 0; y < tmpTexture.Height; y += offsetY) { for (int x = 0; x < tmpTexture.Width; x += offsetX) { float n1 = (float)noise.GetValue(x, y, 0); n1 = (n1 + 3.0f) * 0.25f; n1 = Mathf.Clamp(n1, 0.5f, 1f); float n2 = (float)noise.GetValue(x, y, 0); n2 = (n2 + 3.0f) * 0.25f; n2 = Mathf.Clamp(n2, 0.95f, 1f); Color c = new Color(n1, n1, n1, 1f); SS_Drawing.RectangleFill(tmpTexture, x, y, offsetX, offsetY, c, c); Color current = tmpTexture.GetPixel(x, y); Color c3 = new Color(current.r * n2, current.g * n2, current.b * n2); SS_Drawing.Line(tmpTexture, x, y, x, y + detail, c3); SS_Drawing.Line(tmpTexture, x, y, x + detail, y, c3); } } return(tmpTexture); }
// Use this for initialization void Start() { Debug.Log("Tutorial conversion for http://libnoise.sourceforge.net/tutorials/tutorial2.html"); var perlin = new Perlin(); Debug.Log(string.Format("First value: {0}", perlin.GetValue(_firstValue))); Debug.Log(string.Format("First value, displaced: {0}", perlin.GetValue(_firstValue + _displacement))); Debug.Log(string.Format("Second value: {0}", perlin.GetValue(_secondValue))); }
public Biome GetBiomeByCoordinates(Vector2 coordinates) { // Using coordinates, determine region / continent, then determine biome based on the continent and position float scale = 0.17777f; float x = coordinates.x * scale; float z = coordinates.y * scale; x += (float)Perlin.GetValue(x, 0, z); z += (float)Perlin.GetValue(x, 0, z); Vector2 newCoordinates = new Vector2(x / scale, z / scale); Region region = GetRegionByCoordinates(newCoordinates); return(region.GetBiomeByCoordinates(newCoordinates)); }
public static NoiseWaves GetNoiseWaves(float ax, float ay, float az) { double px = ax / 256d; double py = ay / 256d; double pz = az / 256d; double sx = ax / 160d; double sy = ay / 160d; double sz = az / 160d; double primaryWave = p.GetValue(px, py, pz); double secondaryWave = p.GetValue(sz, sy, sx); return(new NoiseWaves(primaryWave, secondaryWave)); }
public override Double GetValue(double x, double y, double z) { float signal; int curOctave; x *= _frequency; y *= _frequency; z *= _frequency; // Initialize value : get first octave of function; later octaves are weighted float value = Convert.ToSingle(_noise.GetValue(x, y, z)) + _offset; float weight = _gain * value; x *= _lacunarity; y *= _lacunarity; z *= _lacunarity; // inner loop of spectral construction, where the fractal is built for (curOctave = 1; weight > 0.001 && curOctave < _octaveCount; curOctave++) { // prevent divergence if (weight > 1.0) { weight = 1.0f; } signal = (_offset + Convert.ToSingle(_noise.GetValue(x, y, z))); signal *= weight; value += signal; weight *= _gain * signal; // Go to the next octave. x *= _lacunarity; y *= _lacunarity; z *= _lacunarity; } //take care of remainder in _octaveCount float remainder = _octaveCount - (int)_octaveCount; if (remainder > 0.0f) { signal = Convert.ToSingle(_noise.GetValue(x, y, z)); signal *= remainder; value += signal; } return(value); }
public void PerlinPopulate(Perlin perlin, double frequency, double lacunarity, double persistence, int octave, float amplitude, float scale, float stepHeight) { //Random.InitState(seed); //perlin.Seed = seed; perlin.Frequency = frequency; perlin.Lacunarity = lacunarity; perlin.Persistence = persistence; perlin.OctaveCount = octave; int typeShift = Random.Range(0, 21); foreach (HexTile ht in tiles) { //Get next height double perlinVal = perlin.GetValue(ht.hexagon.center.x * scale, ht.hexagon.center.y * scale, ht.hexagon.center.z * scale); double v1 = perlinVal * amplitude;//*i; int h = (int)v1; //Debug.Log(v1); ht.hexagon.scale += h / (1 + (stepHeight / 2f)); //1.5f; if (ht.generation == zeroState) //keep glyphs { int v = Mathf.Abs((int)ht.type + h + typeShift); int t = (v % 12) + 1; //using 12 types ht.type = (TileType)t; } float gP = Random.Range(0f, 1.0f); if (glyphProb > gP) { byte[] newID = new byte[32]; for (int b = 0; b < 32; b++) { newID[b] = (byte)Random.Range(0, 256); } //Create new rune on world (locked in) Rune newRune = new Rune(newID); ht.generation = newRune.tile.uvy; ht.placeObject = false; newRune.hexTile = ht.index; runes.Add(newRune); } float r = Random.Range(0, 1.0f); if (r < 0.24f && ht.generation == zeroState)// populationProb)// && ht.generation == zeroState) { //populate, unless too many neighbors are populated int neighborPopulation = 0; foreach (int htn in ht.neighbors) { if (tiles[htn].placeObject) { neighborPopulation++; } } if (neighborPopulation < 1) { ht.placeObject = true; //ht.passable = false; } } } }
public override void Generate(Map map) { if (Find.World.HasCaves(map.Tile)) { Perlin perlin = new Perlin(0.079999998211860657, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium); Perlin perlin2 = new Perlin(0.15999999642372131, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium); MapGenFloatGrid caves = MapGenerator.Caves; foreach (IntVec3 allCell in map.AllCells) { IntVec3 current = allCell; if (!(caves[current] <= 0.0)) { TerrainDef terrain = current.GetTerrain(map); if (terrain != TerrainDefOf.WaterMovingShallow && terrain != TerrainDefOf.WaterMovingDeep) { float num = (float)perlin.GetValue((double)current.x, 0.0, (double)current.z); float num2 = (float)perlin2.GetValue((double)current.x, 0.0, (double)current.z); if (num > 0.93000000715255737) { map.terrainGrid.SetTerrain(current, TerrainDefOf.WaterShallow); } else if (num2 > 0.550000011920929) { map.terrainGrid.SetTerrain(current, TerrainDefOf.Gravel); } } } } } }
public override void Generate(Map map, GenStepParams parms) { if (Find.World.HasCaves(map.Tile)) { Perlin perlin = new Perlin(0.079999998211860657, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium); Perlin perlin2 = new Perlin(0.15999999642372131, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium); MapGenFloatGrid caves = MapGenerator.Caves; foreach (IntVec3 allCell in map.AllCells) { if (!(caves[allCell] <= 0f) && !allCell.GetTerrain(map).IsRiver) { float num = (float)perlin.GetValue(allCell.x, 0.0, allCell.z); float num2 = (float)perlin2.GetValue(allCell.x, 0.0, allCell.z); if (num > 0.93f) { map.terrainGrid.SetTerrain(allCell, TerrainDefOf.WaterShallow); } else if (num2 > 0.55f) { map.terrainGrid.SetTerrain(allCell, TerrainDefOf.Gravel); } } } } }
public static void GenerateChunk(object o) { Chunk tempChunk = (Chunk)o; tempChunk.Editing = true; for (int x = (int)tempChunk.Position.X; x < (int)tempChunk.Position.X + tempChunk.Size; x++) { for (int z = (int)tempChunk.Position.Z; z < (int)tempChunk.Position.Z + tempChunk.Size; z++) { byte baseHeight = 64; byte variance = 5; double height = (_perlin.GetValue(x, 0, z) + 0.25) * variance + baseHeight; for (int y = (int)tempChunk.Position.Y; y < (int)tempChunk.Position.Y + tempChunk.Size; y++) { if (y < height - 3) { tempChunk.SetVoxel(x, y, z, 1); } else if (y < height - 1) { tempChunk.SetVoxel(x, y, z, 2); } else if (y < height) { tempChunk.SetVoxel(x, y, z, 3); } } } } tempChunk.Editing = false; }
// Token: 0x0600137F RID: 4991 RVA: 0x000955F0 File Offset: 0x000939F0 private static void PeturbVerticesRandomly(float str) { float dmod = 1f; Rand.PushState(); Perlin perlin = new Perlin(0.0070000002160668373, 2.0, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High); Rand.PopState(); List <Vector2> list = AdeptusLightningBoltMeshMaker.verts2D.ListFullCopy <Vector2>(); AdeptusLightningBoltMeshMaker.verts2D.Clear(); int threshold = (list.Count / 4) * 3; for (int i = 0; i < list.Count; i++) { float d = str * (float)perlin.GetValue((double)i, 0.0, 0.0); if (i > threshold) { dmod = 1 - (1 * ((float)(i - threshold) / (list.Count - threshold))); // Log.Message(string.Format("dmod now: {0}", dmod)); } d = d * dmod; // Log.Message(string.Format("d: {0}", d)); Vector2 item = list[i] + d * Vector2.right; AdeptusLightningBoltMeshMaker.verts2D.Add(item); } }
float CellHealthFromNoise(int x, int y) { float distanceWeight = Vector2.DistanceSquared(new Vector2(x, y), new Vector2(Width / 2, Height / 2) + offset) / 100; // Console.WriteLine($"{x}:{y} -> {distanceWeight}"); return((float)((noise.GetValue(x, y, 0) + 1) * 50) + distanceWeight); }
void Start() { Perlin noise = new Perlin(1.0f, 0.2f, 0.2f, 8, seed, QualityMode.High); float scalePos = 20; for (int x = 0; x <= lenght; x++) { for (int y = 0; y < lenght; y++) { for (int z = 0; z <= width; z++) { float noiseX = Mathf.Abs(x) / scalePos; float noiseY = Mathf.Abs(y) / scalePos; float noiseZ = Mathf.Abs(z) / scalePos; double noiseValue = noise.GetValue(noiseX, noiseY, noiseZ); noiseValue += (200.0f - y) / 18; noiseValue /= y / 19.0f; print(noiseValue); if (noiseValue > 0.5f) { Vector3 pos = new Vector3(x, y, z); Instantiate(block, pos, Quaternion.identity); } } } } }
public void CreateHeightMap() { // Set up noise rigged = new RiggedMultifractal(frequency, lacunarity, octaves, seed, quality); perlin = new Perlin(frequency, lacunarity, persistence, octaves, seed, quality); billow = new Billow(frequency, lacunarity, persistence, octaves, seed, quality); //ModuleBase moduleBase = perlin; // Apply noise to the meshes foreach (Transform child in transform) { MeshFilter meshFilter = child.GetComponent <MeshFilter> (); Vector3[] vertices = meshFilter.sharedMesh.vertices; Vector3[] normals = meshFilter.sharedMesh.normals; Color[] colorMap = new Color[vertices.Length]; for (int i = 0; i < vertices.Length; i++) { float magnitude = (float )perlin.GetValue(vertices[i].x / scale, vertices[i].y / scale, vertices[i].z / scale); //float magnitude = (float )rigged.GetValue(vertices[i].x / scale, vertices[i].y / scale, vertices[i].z / scale); vertices [i] = Vector3.MoveTowards(vertices [i], (vertices [i] + normals [i]), magnitude * heightMultiplier); colorMap [i] = gradient.Evaluate((magnitude + 1) * 0.5f); } meshFilter.sharedMesh.vertices = vertices; meshFilter.sharedMesh.colors = colorMap; meshFilter.sharedMesh.RecalculateNormals(); } }
void Texturize(SS_Texture texture, Color targetColor, Color tint, bool highlights, bool shading) { Perlin perlin = new Perlin(0.025, 2, 0.5, 8, Seed, QualityMode.Low); SS_Texture BaseTexture = SS_StellarSprite.GenerateBaseTexture(Seed, texture.Width, texture.Height, 8 * (random.Range(1, 2))); for (int y = texture.Height / 2; y < texture.Height; y++) { for (int x = texture.Width / 2; x < texture.Width; x++) { if (texture.GetPixel(x, y) == targetColor) { Color hullShade = BaseTexture.GetPixel(x, y); // Pixel shade float pixelNoise = (float)perlin.GetValue(x, y, 0); pixelNoise = (pixelNoise + 3.0f) * 0.25f; // 0.5 to 1.0 pixelNoise = Mathf.Clamp(pixelNoise, 0.5f, 1f); hullShade *= tint * pixelNoise; if (shading) { SS_StellarSprite.PixelLighting(texture, x, y, ref hullShade); } hullShade.a = 1.0f; texture.SetPixel(x, y, hullShade); } } } }
private void Shake() { if (isShake) { //perlin noise Perlin xNoise = new Perlin(XFrequency, XLacunarity, XPersistence, XOctaves, XSeed, QualityMode.Medium); Perlin yNoise = new Perlin(YFrequency, YLacunarity, YPersistence, YOctaves, YSeed, QualityMode.Medium); //Transform movement transform.position = originalPosition + Vector3.Scale(new Vector3((float)xNoise.GetValue(i, i, i), (float)yNoise.GetValue(i, i, i), 0), shakeRange); shakeRange = new Vector3(shakeRange.x * -1, shakeRange.y); //increment position along Perlin i++; //Increment timer timer += Time.deltaTime; if (timer >= ShakeTime) { isShake = false; timer = 0; i = 0; transform.position = originalPosition; } } }
public override void Generate(Map map, GenStepParams parms) { if (!Find.World.HasCaves(map.Tile)) { return; } Perlin perlin = new Perlin(0.079999998211860657, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium); Perlin perlin2 = new Perlin(0.15999999642372131, 2.0, 0.5, 6, Rand.Int, QualityMode.Medium); MapGenFloatGrid caves = MapGenerator.Caves; foreach (IntVec3 current in map.AllCells) { if (caves[current] > 0f) { TerrainDef terrain = current.GetTerrain(map); if (!terrain.IsRiver) { float num = (float)perlin.GetValue((double)current.x, 0.0, (double)current.z); float num2 = (float)perlin2.GetValue((double)current.x, 0.0, (double)current.z); if (num > 0.93f) { map.terrainGrid.SetTerrain(current, TerrainDefOf.WaterShallow); } else if (num2 > 0.55f) { map.terrainGrid.SetTerrain(current, TerrainDefOf.Gravel); } } } } }
/// <summary> /// From the VoxelSim project /// http://github.com/N3X15/VoxelSim /// </summary> /// <param name="X"></param> /// <param name="Z"></param> /// <param name="chunksize"></param> /// <returns></returns> public override double[,] Generate(IMapHandler mh, long X, long Z, out double minHeight, out double maxHeight) { Vector3i chunksize = mh.ChunkScale; int x_o = (int)(X * chunksize.X); int z_o = (int)(Z * chunksize.Z); int YH = (int)chunksize.Y - 2; double[,] hm = new double[chunksize.X, chunksize.Z]; minHeight = (double)chunksize.Y; maxHeight = 0; for (int x = 0; x < chunksize.X; x++) { for (int z = 0; z < chunksize.Z; z++) { double height = 1 - Utils.FixLibnoiseOutput(ContinentNoise.GetValue((double)(x + x_o) / 10d, (double)(z + z_o) / 10d, 0)); height *= 0.5; height += 0.25; height = Utils.Clamp(height, 0.1, 1); if (height < minHeight) { minHeight = height; } if (height > maxHeight) { maxHeight = height; } hm[x, z] = height; } } return(hm); }
/*void SpherifyMesh (Mesh mesh) * { * Vector3[] vertices = mesh.vertices; * * for (var i = 0; i < vertices.Length; i++) { * vertices [i] = vertices [i].normalized * radius; * } * * mesh.vertices = vertices; * mesh.RecalculateNormals (); * mesh.RecalculateBounds (); * }*/ void ApplyPerlinNoise(GameObject planet) { Mesh mesh = planet.GetComponent <MeshFilter> ().mesh; Vector3[] vertices = mesh.vertices; Color[] colors = new Color[vertices.Length]; Perlin noiseGenerator = new Perlin(); for (var i = 0; i < vertices.Length; i++) { //float xAngle = Vector3.Angle (Vector3.right, vertices [i]) / noiseSmoothing; //float yAngle = Vector3.Angle (Vector3.up, vertices [i]) / noiseSmoothing; //float noise = Mathf.PerlinNoise (xAngle, yAngle) * noiseIntensity; //float noise = Mathf.PerlinNoise (vertices [i].x + vertices [i].y, vertices [i].z + vertices [i].y); Vector3 noiseVector = new Vector3(vertices [i].x + planet.transform.position.x, vertices [i].y + planet.transform.position.y, vertices [i].z + planet.transform.position.z) / noiseSmoothing; float noise = (float)noiseGenerator.GetValue(noiseVector.x, noiseVector.y, noiseVector.z); vertices [i] = vertices [i].normalized * (radius + noise); colors [i] = noise < 0.3f * noiseIntensity ? Color.blue : Color.green; } mesh.vertices = vertices; mesh.colors = colors; mesh.RecalculateNormals(); mesh.RecalculateBounds(); }
private Tile GenerateTile(int x, int z) { GameObject plane = (GameObject)Instantiate(planeprefab, new Vector3(x * planeSize, 0, z * planeSize), Quaternion.identity); plane.transform.localScale = new Vector3(planeSize * 0.1f, 1, planeSize * 0.1f); plane.transform.parent = transform; Mesh mesh = plane.GetComponent <MeshFilter>().mesh; Vector3[] vertices = mesh.vertices; for (int v = 0; v < vertices.Length; v++) { Vector3 vertex_pos = plane.transform.position + vertices[v] * planeSize / 10; float height = (float)noise.GetValue(vertex_pos * detailScale); vertices[v].y = height * heightScale; } mesh.vertices = vertices; mesh.RecalculateBounds(); mesh.RecalculateNormals(); plane.AddComponent <MeshCollider>(); Tile tile = new Tile(); tile.gameObject = plane; tile.tileX = x; tile.tileZ = z; return(tile); }
private Vector3[] generateUpperVertices(int upperVertCount, float frequencyMultiplier) { //block count == (height - 1) / 3 //vertex count per block == 5 //index count per block == 9 int heightCount = upperVertCount; //height count should be (divisable by three) + 1 Vector3[] height = new Vector3[heightCount]; //*2 + 1 Perlin perlin = new Perlin(); perlin.Seed = DateTime.Now.Millisecond; float x = 0; float multiplier = frequencyMultiplier; for (int i = 0; i < height.Length; i++) { float value = (float)perlin.GetValue(x + 0.005f * i, 0, 0); value += 1; value = value / 2; value += 0.3f; height[i] = new Vector3(x, value, 0); x += 1.5f / (multiplier + 500); } return(height); }
public override double GetValue(double x, double y, double z) { // Get the values from the three noise::module::Perlin noise modules and // add each value to each coordinate of the input value. There are also // some offsets added to the coordinates of the input values. This prevents // the distortion modules from returning zero if the (x, y, z) coordinates, // when multiplied by the frequency, are near an integer boundary. This is // due to a property of gradient coherent noise, which returns zero at // integer boundaries. double x0 = x + (12414.0 / 65536.0); double y0 = y + (65124.0 / 65536.0); double z0 = z + (31337.0 / 65536.0); double x1 = x + (26519.0 / 65536.0); double y1 = y + (18128.0 / 65536.0); double z1 = z + (60493.0 / 65536.0); double x2 = x + (53820.0 / 65536.0); double y2 = y + (11213.0 / 65536.0); double z2 = z + (44845.0 / 65536.0); double xDistort = x + (xDistortModule.GetValue(x0, y0, z0) * Power); double yDistort = y + (yDistortModule.GetValue(x1, y1, z1) * Power); double zDistort = z + (zDistortModule.GetValue(x2, y2, z2) * Power); // Retrieve the output value at the offsetted input value instead of the // original input value. return(SourceModule.GetValue(xDistort, yDistort, zDistort)); }
// Token: 0x0600137F RID: 4991 RVA: 0x000955F0 File Offset: 0x000939F0 private static void PeturbVerticesRandomly(SimpleCurve strDist, SimpleCurve strTime = null) { float dmod = 1f; Perlin perlin = new Perlin(0.0070000002160668373, 2.0, 0.5, 6, Rand.Range(0, int.MaxValue), QualityMode.High); List <Vector2> list = LightningLaserBoltMeshMaker.verts2D.ListFullCopy <Vector2>(); LightningLaserBoltMeshMaker.verts2D.Clear(); int threshold = (list.Count / 4) * 3; // Log.Message("PeturbVerticesRandomly Points: " + strDist.PointsCount + " " + strDist.Points.ToString()); for (int i = 0; i < list.Count; i++) { float f = Mathf.InverseLerp(0, list.Count, i); float d = strDist.Evaluate(f) * (float)perlin.GetValue((double)i, 0.0, 0.0); // Log.Message("str " + d +" @ "+ f); if (i > threshold) { dmod = 1 - (1 * ((float)(i - threshold) / (list.Count - threshold))); // Log.Message(string.Format("dmod now: {0}", dmod)); } d = d * dmod; // Log.Message(string.Format("d: {0}", d)); Vector2 item = list[i] + d * Vector2.right; LightningLaserBoltMeshMaker.verts2D.Add(item); } }
public static float[,] GenerateNoiseMap(int worldWidth, int worldHeight, double frequency, double lacunarity, double persistance, int octaves, int seed) { Perlin perlin = new Perlin(frequency, lacunarity, persistance, octaves, seed, QualityMode.High); //var noise = new Noise2D(worldWidth, worldHeight, perlin); //var data = noise.GetData(); //return data; float[,] map = new float[worldWidth, worldHeight]; for (int y = 0; y < worldHeight; y++) { for (int x = 0; x < worldWidth; x++) { float _x = x; float _y = y; map[x, y] = (float)perlin.GetValue(_x, 0.0f, _y); } } return(map); }
public override void GenerationBasicTerrain(Chunk chunk) { if (_perlin == null) { _perlin = new Perlin() { Seed = chunk.World.Seed, Frequency = 0.5, Persistence = 0.25 }; } for (int x = 0; x < 16; x++) { for (int z = 0; z < 16; z++) { int noise = (int)(_perlin.GetValue((double)x / 15d + chunk.X, 0, (double)z / 15d + chunk.Z) * 5) + 10; chunk.SetBlock(x, noise, z, 2); for (int y = noise - 1; y >= 0; y--) { chunk.SetBlock(x, y, z, 3); } } } }
public static void Main(string[] args) { Color darkGround = new Color(0, 125, 0); Color lightGround = new Color(50, 255, 50); Color sky = new Color(150, 150, 255); Keyboard keyboard = new Keyboard(); keyboard.Initialize(); Perlin noise = new Perlin { Seed = new Random().Next() }; DateTime start = DateTime.Now; while (true) { double t = (DateTime.Now - start).TotalSeconds; foreach (Key key in Keys.All) { double noiseAt = (noise.GetValue(key.X * 0.2, t * 0.3, 0) * 0.5 + 0.5) * Keys.KeyboardHeight * 0.6 + 1; keyboard.SetKeyColor(key, Color.Gradient(new double[] { 0, noiseAt - 1, noiseAt + 1, Keys.KeyboardHeight }, new Color[] { sky, sky, lightGround, darkGround }, key.Y)); } Thread.Sleep(1000 / 30); keyboard.Update(); } }
public CaveValue GetValue(float x, float y, float z, int height) { float xd = x + ((float)_xDistort.GetValue(x + X0, y + Y0, z + Z0) * _power); float yd = y + ((float)_yDistort.GetValue(x + X1, y + Y1, z + Z1) * _power); float zd = z + ((float)_zDistort.GetValue(x + X2, y + Y2, z + Z2) * _power); return(_cave.GetValue(xd, yd, zd, height)); }
public override double GetValue(double x, double y, double z) { double x2 = x + m_xDistort.GetValue(x + 0.189422607421875, y + 0.99371337890625, z + 0.4781646728515625) * m_power; double y2 = y + m_yDistort.GetValue(x + 0.4046478271484375, y + 0.276611328125, z + 0.9230499267578125) * m_power; double z2 = z + m_zDistort.GetValue(x + 0.82122802734375, y + 0.1710968017578125, z + 0.6842803955078125) * m_power; return(modules[0].GetValue(x2, y2, z2)); }
/*void SpherifyMesh (Mesh mesh) { Vector3[] vertices = mesh.vertices; for (var i = 0; i < vertices.Length; i++) { vertices [i] = vertices [i].normalized * radius; } mesh.vertices = vertices; mesh.RecalculateNormals (); mesh.RecalculateBounds (); }*/ void ApplyPerlinNoise (GameObject planet) { Mesh mesh = planet.GetComponent<MeshFilter> ().mesh; Vector3[] vertices = mesh.vertices; Color[] colors = new Color[vertices.Length]; Perlin noiseGenerator = new Perlin (); for (var i = 0; i < vertices.Length; i++) { //float xAngle = Vector3.Angle (Vector3.right, vertices [i]) / noiseSmoothing; //float yAngle = Vector3.Angle (Vector3.up, vertices [i]) / noiseSmoothing; //float noise = Mathf.PerlinNoise (xAngle, yAngle) * noiseIntensity; //float noise = Mathf.PerlinNoise (vertices [i].x + vertices [i].y, vertices [i].z + vertices [i].y); Vector3 noiseVector = new Vector3 (vertices [i].x + planet.transform.position.x, vertices [i].y + planet.transform.position.y, vertices [i].z + planet.transform.position.z) / noiseSmoothing; float noise = (float)noiseGenerator.GetValue (noiseVector.x, noiseVector.y, noiseVector.z); vertices [i] = vertices [i].normalized * (radius + noise); colors [i] = noise < 0.3f * noiseIntensity ? Color.blue : Color.green; } mesh.vertices = vertices; mesh.colors = colors; mesh.RecalculateNormals (); mesh.RecalculateBounds (); }