// do a test run on the distribution curve
    public void TestDistribution()
    {
        RawImage setImage = FindObjectOfType <RawImage>();

        // set the title text
        title.text = "Distribution of " + useThisManyNumbers.ToString() + " Random Numbers";

        // old version
        // find out how many "stacks" of numbers are there, create an array for them
//		int highestPossibleX =  Mathf.RoundToInt(visualizeDistribution.CurveRect.MaxX);
//		int lowestPossibleX = Mathf.RoundToInt(visualizeDistribution.CurveRect.MinX);
//		int slotsNeeded = (highestPossibleX - lowestPossibleX) + 1; // zero indexing
//		int[] numbers = new int[slotsNeeded];
//		for (int i = 0; i < useThisManyNumbers; i++) {
//			int r = visualizeDistribution.RandomInt();
//			r -= lowestPossibleX; // move lowest point of curve to zero
//			numbers[r]++;
//		}

        // fill array with ints
        int highestPossibleX = Mathf.RoundToInt(visualizeDistribution.CurveRect.MaxX);
        int lowestPossibleX  = Mathf.RoundToInt(visualizeDistribution.CurveRect.MinX);
        int xRange           = highestPossibleX - lowestPossibleX;

        int[] numbers = new int[imageWidth];
        for (int i = 0; i < useThisManyNumbers; i++)
        {
            float randomFloat = visualizeDistribution.RandomFloat();
            randomFloat -= lowestPossibleX;                // move lowest point of curve to zero
            randomFloat /= xRange;                         // normalize
            randomFloat *= (imageWidth - 1);               // then scale to image width. -1 because zero indexing
            int randomInt = Mathf.FloorToInt(randomFloat); // make int

            if (randomInt < imageWidth)
            {
                numbers[randomInt]++;                 // add to stats array
            }
//			else
//				Debug.Log ("Dropped number " + randomFloat);
        }

        // label the axes
        UpdateNumberLabels(lowestPossibleX, highestPossibleX);

        //visualizer.VisualizeStats(numbers, changeCamSize);
        Texture2D tex = VisualizeStats(numbers);

        setImage.texture = tex;
    }
Esempio n. 2
0
    // rescale each transform of objects to resize to a random number from RandomDistribution
    public void RandomizeSizes()
    {
        if (randomDistribution == null)
        {
            Debug.LogError("No RandomDistribution assigned to ObjectResizer!");
        }

        foreach (Transform t in allTransforms)
        {
            float size = baseSize;
            float r    = randomDistribution.RandomFloat();
            r           /= 100f;   // r comes in percent
            size        *= r;
            t.localScale = new Vector3(size, size, size);
        }
    }