// Use this for initialization
    void Start()
    {
        mom = (GameObject)Instantiate(Resources.Load("Blob"));
        dad = (GameObject)Instantiate(Resources.Load("Blob"));

        //Separate the two so they aren't covering each other
        mom.transform.position = new Vector2(3, transform.position.y);
        dad.transform.position = new Vector2(-3, transform.position.y);

        //Add markings to the dad
        //GO = (GameObject)Instantiate(Resources.Load("dogmarkings"));
        //GO.transform.parent = dad.transform;
        //GO.transform.position = new Vector3(-3, transform.position.y, -1);

        //Flip the Mommy around so that she faces the Daddy
        mom.transform.eulerAngles = new Vector2(0, 180);

        //Make the Mom red and the Dad green
        LABColor c1 = new LABColor(Color.yellow);
        LABColor c2 = new LABColor(Color.red);
        LABColor c3 = new LABColor(Color.white);
        LABColor c4 = new LABColor(Color.black);
        mom.GetComponent<SpriteRenderer>().color = c1.ToColor();
        dad.GetComponent<SpriteRenderer>().color = c2.ToColor();

        mom.GetComponent<Blob>().addGene<LABColor>("Color", c1, 0, c3, 0);
        dad.GetComponent<Blob>().addGene<LABColor>("Color", c2, 0, c4, 0);

        child = Punnett.cross(mom.GetComponent<Blob>(), dad.GetComponent<Blob>());
        child.transform.position = new Vector2(0, transform.position.y);

        child.GetComponent<SpriteRenderer>().color = child.GetComponent<Blob>().color.ToColor();
    }
    //call SetColors AFTER sorting
    public void SetColors()
    {
        //count number of animals (sorted such that animal nodes come first)
        int seriesCount = seriesNodes.Count;
        int plantMax    = 7;
        int animalCount = 0;

        while (animalCount < seriesCount && seriesNodes [animalCount] > plantMax)
        {
            animalCount++;
        }
        int plantCount = seriesCount - animalCount;

        //get color range from LABColor for best spectrum (converts RGB to linear)
        //vary color from red for animals and from green for plants
        LABColor firstColor      = new LABColor(new Color(1.00f, 0.00f, 0.00f));
        LABColor lastAnimalColor = new LABColor(new Color(0.50f, 0.50f, 1.00f));                //incorporate blue
        LABColor firstPlantColor = new LABColor(new Color(0.50f, 0.50f, 0.00f));
        LABColor lastColor       = new LABColor(new Color(0.00f, 1.00f, 0.00f));

        float[] deltaAnimalColor = LABColor.Diff(lastAnimalColor, firstColor);
        for (int j = 0; j < deltaAnimalColor.Length; j++)
        {
            deltaAnimalColor[j] = deltaAnimalColor[j] / (Mathf.Max(1.0f, (float)animalCount - 1.0f));
        }
        if (plantCount == 1)
        {
            firstPlantColor = lastColor;
        }
        float[] deltaPlantColor = LABColor.Diff(lastColor, firstPlantColor);
        for (int j = 0; j < deltaPlantColor.Length; j++)
        {
            deltaPlantColor[j] = deltaPlantColor[j] / (Mathf.Max(1.0f, (float)plantCount - 1.0f));
        }
        LABColor currColor = firstColor;

        //loop through series to set series' colors
        for (int i = 0; i < seriesCount; i++)
        {
            if (i == animalCount)                 //first plant
            {
                currColor = firstPlantColor;
            }
            Color color = LABColor.ToColor(currColor);

            string name = seriesLabels [i];
            seriesColors [name]    = color;
            seriesColorsHex [name] = Functions.ColorToHex(color);

            currColor.Increment(i < animalCount ? deltaAnimalColor : deltaPlantColor);
        }
    }
Exemple #3
0
    public void modifyMaterial(Dictionary <string, object> properties, Material[] materials)
    {
        string timeString    = UIDataManager.Instance.MonthKeys[UIDataManager.Instance.TimeIndex];
        string heightDataKey = UIDataManager.Instance.MonthKeys[UIDataManager.Instance.TimeIndex];
        string sideColorDataKey;

        if ((float.Parse(timeString.Substring(0, 4))) > 2005)
        {
            sideColorDataKey = "2010-minorityPercent";
        }
        else
        {
            sideColorDataKey = "2000-minorityPercent";
        }

        float minDataValue = 0;
        float maxDataValue = 100;

        float    dataValue    = minDataValue;
        Material sideMaterial = materials[1];

        if (properties.ContainsKey(sideColorDataKey) && properties.ContainsKey(heightDataKey))
        {
            if (float.TryParse(properties[sideColorDataKey].ToString(), out dataValue))
            {
                float    colorPercent      = (dataValue - minDataValue) / (maxDataValue - minDataValue);
                LABColor minColorVal       = new LABColor(0f, 25f, -100f);
                LABColor maxColorVal       = new LABColor(100f, 0f, 0f);
                LABColor sideMaterialColor = LABColor.Lerp(maxColorVal, minColorVal, colorPercent);
                sideMaterial.SetColor("_Color", sideMaterialColor.ToColor());
            }
        }
        else
        {
//			materials[0] = new Material(sideMaterial.shader);
//			// TODO: set top material to missing data material
//			materials[0].SetColor("_Color", new Color(229f / 255f, 117f / 255f, 52f / 255f, 1f));
//			materials [0].mainTexture = sideMaterial.mainTexture;
//			materials = new Material[0];
        }
    }
Exemple #4
0
 // function for converting an instance of LABColor to Color
 public Color ToColor()
 {
     return(LABColor.ToColor(this));
 }