Example #1
0
        public static void RandomOffsetNodes(List <LogicHex> nodes, int maxDistance, int seed)
        {
            for (int i = 0; i < nodes.Count; ++i)
            {
                LogicHex node = nodes[i];

                int qNoise = LogicPerlinNoise.Noise((node.q << 12) + seed, (node.s << 15) + seed, seed * 7, maxDistance);
                int rNoise = LogicPerlinNoise.Noise((node.q << 14) + seed, (node.s << 13) + seed, seed * 10, maxDistance);

                nodes[i] = nodes[i].Add(new LogicHex(qNoise, rNoise));
            }
        }
Example #2
0
        public static void AltitudeAbsNoise(LogicHexMap map, int octave, int seed, int percent)
        {
            for (int r = 0; r < map.height; ++r)
            {
                for (int q = 0; q < map.width; ++q)
                {
                    int         tile     = map.Get(q, r);
                    int         altitude = LogicTile.GetAltitude(tile);
                    LogicPoint3 pos      = HexToLogicPos(new LogicHex(q, r), altitude * ALTITUDE_SCALE);


                    int noise = LogicPerlinNoise.Noise((pos.x << octave) + seed, (pos.z << octave) + seed, seed << 2, LogicTween.SCALE);


                    int  distanceToMiddle = (noise - LogicTween.SCALE_HALF);
                    bool flip             = false;
                    if (distanceToMiddle < 0)
                    {
                        distanceToMiddle = -distanceToMiddle;
                        flip             = true;
                    }
                    distanceToMiddle = LogicTween.QuadIn(distanceToMiddle * 2) / 2;
                    if (flip)
                    {
                        distanceToMiddle = -distanceToMiddle;
                    }

                    noise = LogicTween.SCALE_HALF + distanceToMiddle;
                    noise = noise / (LogicTween.SCALE / LogicTile.MAX_ALTITUDE);



                    /*int noise = LogicPerlinNoise.Noise((pos.x << octave) + seed, (pos.z << octave) + seed, seed << 2, LogicTile.MAX_ALTITUDE*2);
                     * noise -= LogicTile.MAX_ALTITUDE;
                     * if (noise < 0)
                     *  noise = -noise;
                     *
                     *
                     * LogicTween.QuadIn();
                     */

                    //noise = LogicPerlinNoise.ScaleNoise(noise, LogicTile.MAX_ALTITUDE);

                    altitude = Lerp(altitude, noise, percent);
                    tile     = LogicTile.SetAltitude(tile, altitude);



                    map.Set(q, r, tile);
                }
            }
        }
Example #3
0
        public static void AltitudeNoise(LogicHexMap map, int octave, int seed, int percent)
        {
            for (int r = 0; r < map.height; ++r)
            {
                for (int q = 0; q < map.width; ++q)
                {
                    int         tile     = map.Get(q, r);
                    int         altitude = LogicTile.GetAltitude(tile);
                    LogicPoint3 pos      = HexToLogicPos(new LogicHex(q, r), altitude * ALTITUDE_SCALE);

                    int noise = LogicPerlinNoise.Noise((pos.x << octave) + seed, (pos.z << octave) + seed, seed << 2, LogicTile.MAX_ALTITUDE);

                    altitude = Lerp(altitude, noise, percent);
                    tile     = LogicTile.SetAltitude(tile, altitude);

                    map.Set(q, r, tile);
                }
            }
        }
Example #4
0
        /*public static void GenerateTile(GeneratedTile tile, int x, int y, int seed, int step)
         * {
         *  tile.terrain = TerrainType.Grass;
         *  tile.altitude = LogicTween.SCALE_HALF;
         *
         *  if (step == 1) return;
         *
         *  int noise1 = Noise(x, y, 3, seed, LogicTween.SCALE);
         *  int noise1b = Noise(x, y, 3, seed + 12345, LogicTween.SCALE);
         *
         *  int noise2 = Noise(x, y, 5, seed, LogicTween.SCALE);
         *  int noise2b = Noise(x, y, 5, seed + 12345, LogicTween.SCALE);
         *
         *  int noise3 = Noise(x, y, 6, seed, LogicTween.SCALE);
         *  int noise3b = Noise(x, y, 6, seed + 12345, LogicTween.SCALE);
         *
         *  tile.altitude = noise1;
         *
         *  if (step == 2) return;
         *
         *  tile.altitude = Lerp(tile.altitude, noise2, 70);
         *
         *  if (step == 3) return;
         *
         *  tile.altitude = Lerp(tile.altitude, noise3, 10);
         *
         *  if (step == 4) return;
         *
         *  tile.altitude = Plateau(tile.altitude, LogicTween.SCALE_HALF);
         *
         *  if (step == 5) return;
         *
         *  //if (tile.altitude < LogicTween.SCALE_HALF - 10)
         *  //    tile.altitude = Lerp(tile.altitude, tile.altitude / 2, 20);
         *
         *  if (step == 6) return;
         *
         *  const int errorMargin = 16;
         *  if (tile.altitude < LogicTween.SCALE_HALF - errorMargin)
         *  {
         *      tile.terrain = TerrainType.Sand;
         *  }
         *  else if(tile.altitude < LogicTween.SCALE_HALF + errorMargin)
         *  {
         *      tile.terrain = TerrainType.Dirt;
         *  }
         *
         *  if (step == 7) return;
         *
         *  tile.altitude = Lerp(tile.altitude, noise2b, 10);
         * }*/

        public static int Noise(int x, int y, int octave, int seed, int scale)
        {
            return(LogicPerlinNoise.Noise((x << octave) + seed, (y << octave) + seed, seed << 2, scale));
        }