using UnityEngine;
using System.Collections;

public class ColourCalc : MonoBehaviour {

	//colours: red blue green magenta yellow cyan orange crimson violet cobalt turquoise lime gray white
	
	static public LightColour MixColours(LightColour colour1, LightColour colour2){
		if(colour1.Equals(colour2))
			return colour1;
		
		if(colour1.Equals("gray") || colour1.Equals("gray"))
			return new LightColour("gray");
		
		//base mix
		if(TestColour(colour1, colour2, "red", "blue"))
			return new LightColour("magenta");
		
		if(TestColour(colour1, colour2, "red", "green"))
			return new LightColour("yellow");
		
		if(TestColour(colour1, colour2, "green", "blue"))
			return new LightColour("cyan");
		
		//base + opposite
		if(TestColour(colour1, colour2, "green", "magenta"))
			return new LightColour("white");
		
		if(TestColour(colour1, colour2, "blue", "yellow"))
			return new LightColour("white");
		
		if(TestColour(colour1, colour2, "red", "cyan"))
			return new LightColour("white");
		
		//base colour + "children"
		
		if(TestColour(colour1, colour2, "red", "yellow"))
			return new LightColour("orange");
		
		if(TestColour(colour1, colour2, "red", "magenta"))
			return new LightColour("crimson");
		
		if(TestColour(colour1, colour2, "blue", "magenta"))
			return new LightColour("violet");
		
		if(TestColour(colour1, colour2, "blue", "cyan"))
			return new LightColour("cobalt");
		
		if(TestColour(colour1, colour2, "green", "cyan"))
			return new LightColour("turquoise");
		
		if(TestColour(colour1, colour2, "green", "yellow"))
			return new LightColour("lime");
		
		//else return "unpure" colour
		return new LightColour("gray");
	}
	
	static private bool TestColour(LightColour colour1, LightColour colour2, string test1, string test2){
		
		if((colour1.Equals(test1) && colour2.Equals(test2)) || (colour1.Equals(test2) && colour2.Equals(test1)))
			return true;
		
		return false;
	}
	
	
	
	static public Color RGB(LightColour col){
		return RGB(col.GetColourAsString());
	}
	
	static public Color RGB(string col){
		
		switch(col){
			
			case "red":
				return new Color(1f, 0f, 0f, 1f);
			
			case "blue":
				return new Color(0f, 0f, 1f, 1f);
			
			case "green":
				return new Color(0f, 1f, 0f, 1f);
			
			case "magenta":
				return new Color(1f, 0f, 1f, 1f);
			
			case "yellow":
				return new Color(1f, 235f/255f, 4f/255f, 1f);

			case "cyan":
				return new Color(0f, 1f, 1f, 1f);
			
			case "orange":
				return new Color(232f/255f, 100f/255f, 27f/255f, 1f);
			
			case "crimson":
				return new Color(227f/255f, 0f, 123f/255f, 1f);
			
			case "violet":
				return new Color(103f/255f, 8f/255f, 123f/255f, 1f);
			
			case "cobalt":
				return new Color(63f/255f, 188f/255f, 239f/255f, 1f);
			
			case "turquoise":
				return new Color(62f/255f, 184f/255f, 180f/255f, 1f);

			case "lime":
				return new Color(124f/255f, 198f/255f, 35f/255f, 1f);
			
			case "white":
				return new Color(1f, 1f, 1f, 1f);

			case "gray":
			default:
				return new Color(84f/255f, 84f/255f, 84f/255f, 1f);		
		}
		
		
		
		
		
		
	}

}
