using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GenerateBackground : MonoBehaviour {

    public float minRadius;
    public float maxRadius;
    public float minSize;
    public float maxSize;
    public int minItems;
    public int maxItems;

    public Sprite[] sprites;

	void Start () {
        var itemCount = Random.Range(minItems, maxItems);
        for (int i=0; i<itemCount; i++)
        {
            // get position
            var x = Random.Range(-1f, 1f);
            var localRadius = Mathf.Sin(Mathf.Acos(x));
            var theta = Random.Range(0, Mathf.PI*2);
            var y = Mathf.Sin(theta) * localRadius;
            var z = Mathf.Cos(theta) * localRadius;
            var sprite = sprites[Random.Range(0, sprites.Length)];
            var pivot = new GameObject();
            pivot.AddComponent<SlowlyRotate>();
            var go = new GameObject();
            var sr = go.AddComponent<SpriteRenderer>();
            sr.sprite = sprite;
            go.transform.SetParent(pivot.transform);
            pivot.transform.SetParent(transform);
            go.transform.localPosition = new Vector3(x, y, z) * Random.Range(minRadius, maxRadius);
            go.transform.LookAt(Vector3.zero);
            go.transform.Rotate(new Vector3(0, 0, 1), Random.Range(0f, 360f));
            var scale = Random.Range(minSize, maxSize);
            go.transform.localScale = new Vector3(scale, scale, scale);
        }

	}
}
