示例#1
0
    void MakeRandom(int seed)
    {
        var psoRender = randomPreset.GetComponent <PSORender>();

        var rnd = new System.Random(seed);

        randomPreset.seed = (int)DateTime.UtcNow.Ticks;

        int p = rnd.Range(0, 100);

        if (p < 50)
        {
            randomPreset.problem = PSOConfig.Problem.PerlinLandscape;

            randomPreset.perlinOctaves            = rnd.Range(4, 10);
            randomPreset.perlinAmplitude          = rnd.Range(15.0f, 25.0f);
            randomPreset.perlinFrequency.x        = rnd.Range(0.02f, 0.1f);
            randomPreset.perlinFrequency.y        = randomPreset.perlinFrequency.x * rnd.Gaussian(1.0f, 0.1f);
            randomPreset.perlinAmplitudePerOctave = rnd.Gaussian(0.5f, 0.1f);
            randomPreset.perlinFrequencyPerOctave = rnd.Gaussian(2.0f, 0.5f);
            randomPreset.perlinOffset.x           = rnd.Range(-1000.0f, 1000.0f);
            randomPreset.perlinOffset.y           = rnd.Range(-1000.0f, 1000.0f);

            psoRender.materialOverride = materialsLandscape[rnd.Range(0, materialsLandscape.Length)];
            psoRender.yScale           = 1.0f;
        }
        else
        {
            if (p < 75)
            {
                randomPreset.problem = PSOConfig.Problem.ImageSaturation;
            }
            else
            {
                randomPreset.problem = PSOConfig.Problem.ImageValue;
            }

            randomPreset.image       = images[rnd.Range(0, images.Length)];
            randomPreset.invertImage = true;

            psoRender.yScale           = -rnd.Gaussian(20.0f, 4.0f);
            psoRender.materialOverride = materialsImage[rnd.Range(0, materialsImage.Length)];
        }

        psoRender.fogOfFunction = (rnd.Range(0, 100) < 50);
    }
    protected override void FillTexture(Color[] colors)
    {
        var rnd = new System.Random(seed);

        for (int y = 0; y < height; y++)
        {
            for (int x = 0; x < width; x++)
            {
                int index = y * width + x;

                float r;
                if (gaussian)
                {
                    r = Mathf.Clamp01(rnd.Gaussian(mean, stdDev / 0.3f));
                }
                else
                {
                    r = rnd.Range(0.0f, 1.0f);
                }
                colors[index] = new Color(r, r, r, 1);
            }
        }
    }
 public static int Gaussian(this System.Random gen, int mean, int stdDev)
 {
     return((int)gen.Gaussian((float)mean, (float)stdDev));
 }