10,000 primitive objects for Aesthetics of Computation.

Press 'r' to reset.


public class Generate : MonoBehaviour

{

    [SerializeField]

    List<GameObject> shapePrefabs;

    private List<GameObject> shapes;

    private int size = 100;

    private float coef = 1.25f;

    // Start is called before the first frame update

    void Start()

    {

        CreateShapes();

    }

    // Update is called once per frame

    void Update()

    {

        if (Input.GetKeyDown(KeyCode.R))

        {

            CreateShapes();

        }

    }

    public void CreateShapes()

    {

        if(shapes != null && shapes.Count > 0)

        {

            foreach(GameObject g in shapes)

            {

                Destroy(g);

            }

        }

        shapes = new List<GameObject>();

        for (int i = 0; i < size; i++)

        {

            for (int j = 0; j < size; j++)

            {

                shapes.Add(

                    Instantiate(shapePrefabs[Random.Range(0, 4)], new Vector3(coef * i - (coef * size / 2.0f), 0, coef * j - (coef * size / 2.0f)), Quaternion.Euler(Random.Range(0, 360), Random.Range(0, 360), Random.Range(0, 360)))

                );

                shapes[shapes.Count - 1].transform.localScale = new Vector3(Random.Range(0, 1.0f), Random.Range(0, 1.0f), Random.Range(0, 1.0f));

            }

        }

    }

}


Leave a comment

Log in with itch.io to leave a comment.