Exemple #1
0
    void Awake()
    {
        // Create random points
        int n = seed;

        points = new List <Vec3>();

        switch (usedGenerator)
        {
        case Generator.Halton:
            for (int i = 0; i < pointNumber; i++)
            {
                // Random sparse distribution
                Vec3 temp = HaltonSequence.Halton2D(n, bases[0], bases[1]);
                points.Add(new Vec3(temp.X * boundaries[0] + transform.position.x,
                                    temp.Y * boundaries[1] + transform.position.y,
                                    transform.position.z));
                n++;
            }
            break;

        case Generator.Poisson:
            RandGen.Init(seed);
            poissonGen = new PoissonDisk2D(minimalDistance, boundaries[0], boundaries[1],
                                           maxAttemp);
            poissonGen.BuildSample(pointNumber);
            foreach (Vec3 point in poissonGen)
            {
                points.Add(point);
            }
            break;

        default:
            throw new NotImplementedException();
        }


        // Place camera
        var cam = Camera.main;

        cam.transform.position = new Vector3(boundaries[0] / 2.0f, boundaries[1] / 2.0f, -0.8f * Mathf.Max(boundaries));
    }
Exemple #2
0
    // Use this for initialization
    void Awake()
    {
        colorsLength = colors.Length;
        int n = sequenceInit;

        points       = new Vector3[pointNumber];
        pointsObject = new GameObject[pointNumber];

        for (int i = 0; i < points.Length; i++)
        {
            // Random sparse distribution
            points[i] = HaltonSequence.Halton2D(n, bases[0], bases[1]).AsVector3();
            // Scale to boundaries and translate based on generator position
            points[i].x *= boundaries[0];
            points[i].x += transform.position.x;
            points[i].y *= boundaries[1];
            points[i].y += transform.position.y;
            points[i].z += transform.position.z;

            // Create a shape using points coordinates
            var newShape = Instantiate(shape);
            newShape.transform.SetParent(this.transform);
            newShape.transform.position   = points[i];
            newShape.transform.localScale = new Vector3(ShapeScale, ShapeScale, ShapeScale);

            // Random color
            newShape.GetComponent <MeshRenderer>().materials[0].color = colors[Random.Range(0, colorsLength)];

            // Keep track of shape
            pointsObject[i] = newShape;
            n++;
        }

        // Place camera
        var cam = Camera.main;

        cam.transform.position = new Vector3(boundaries[0] / 2.0f, boundaries[1] / 2.0f, -0.8f * Mathf.Max(boundaries));
    }