// Use this for initialization
	void Start()
	{
		// setup components
		lt = GetComponent<Light>();
		// setup hsb color
		col = new HSBColor(hue, saturation, brightness);
	}
	public void CloseToWallTint(float distance)
	{
		HSBColor tempColor = new HSBColor (bgMat.color);
		distance = Mathf.Clamp(50 - distance, 0, tempColor.b);
		tempColor.b -= distance;
		bgMat.SetColor ("_EmissionColor", tempColor.ToColor());
	}
Exemple #3
0
    // Update is called once per frame
    void Update()
    {
        if (HSLToRGB) {
            hsl = new HSBColor(h, s, l);
            rgbCol = hsl.ToColor();

            renderer.material.color = rgbCol;

            r = rgbCol.r;
            g = rgbCol.g;
            b = rgbCol.b;
        } else {
            hsl = HSBColor.FromColor(rgbCol);
            Color temp = hsl.ToColor();

            renderer.material.color = temp;

            h = hsl.h;
            s = hsl.s;
            l = hsl.b;
            r = temp.r;
            g = temp.g;
            b = temp.b;
        }
    }
Exemple #4
0
    public static HSBColor FromColor( Color color )
    {
        HSBColor result = new HSBColor( 0f, 0f, 0f, color.a );
        RGBToHSV( color, out result.h, out result.s, out result.b );

        return result;
    }
Exemple #5
0
    private void OnEnable()
    {
      lightModes = new string[2];
      lightModes[0] = @"UnLit";
      lightModes[1] = @"BumpLit";

      spriteRenderer = this.GetComponent<SpriteRenderer>();

      sunLight = this.GetComponent<Light>();

      hsbColor = new HSBColor(Color.white);
      hsbColor.s = 1.0f;

      if (GameObject.Find("FlareSpawner0") != null)
      {
        flareSpawners.Add(GameObject.Find("FlareSpawner0").GetComponent<Spawner>());
        flareSpawners[0].enabled = false;
      }

      if (GameObject.Find("FlareSpawner1") != null)
      {
        flareSpawners.Add(GameObject.Find("FlareSpawner1").GetComponent<Spawner>());
        flareSpawners[1].enabled = false;
      }

      if (GameObject.Find("FlareSpawner2") != null)
      {
        flareSpawners.Add(GameObject.Find("FlareSpawner2").GetComponent<Spawner>());
        flareSpawners[2].enabled = false;
      }
    }
    public Color HSVToColor(HSBColor hsbColor)
    {
        float r = hsbColor.b;
        float g = hsbColor.b;
        float b = hsbColor.b;
        if (hsbColor.s != 0)
        {
            float max = hsbColor.b;
            float dif = hsbColor.b * hsbColor.s;
            float min = hsbColor.b - dif;

            float h = hsbColor.h * 360f;

            if (h < 60f)
            {
                r = max;
                g = h * dif / 60f + min;
                b = min;
            }
            else if (h < 120f)
            {
                r = -(h - 120f) * dif / 60f + min;
                g = max;
                b = min;
            }
            else if (h < 180f)
            {
                r = min;
                g = max;
                b = (h - 120f) * dif / 60f + min;
            }
            else if (h < 240f)
            {
                r = min;
                g = -(h - 240f) * dif / 60f + min;
                b = max;
            }
            else if (h < 300f)
            {
                r = (h - 240f) * dif / 60f + min;
                g = min;
                b = max;
            }
            else if (h <= 360f)
            {
                r = max;
                g = min;
                b = -(h - 360f) * dif / 60 + min;
            }
            else
            {
                r = 0;
                g = 0;
                b = 0;
            }
        }

        return new Color(Mathf.Clamp01(r), Mathf.Clamp01(g), Mathf.Clamp01(b), hsbColor.a);
    }
 // Update is called once per frame
 void Update()
 {
     if(main != oldMain){
         mainHSB = HSBColor.FromColor(main);
         UpdateColors();
         oldMain = main;
     }
 }
	void GenerateNewColor()
	{
		HSBColor newColor = new HSBColor(Random.value, saturation, brightness, alpha);

		renderer.material.color = newColor.ToColor();


	}
	// Update is called once per frame
	void Update ()
	{
		HSBColor newColor = new HSBColor(Random.value,saturation,brightness,alpha);
		
		foreach(Material mat in materialsToChange)
		{	
			mat.color = newColor.ToColor();
		}
	}
    private void OnEnable()
    {
      spriteColorOutline = gameObject.GetComponent<SpriteColorOutline>();

      hsbColor = new HSBColor(Color.white);
      hsbColor.s = 1.0f;

      originalOutlineSize = spriteColorOutline.outlineSize;
    }
    public List<Color> GetComplementary(int colorsNum)
    {
        List<Color> colors = new List<Color>();

        for(int i = 0; i < colorsNum; i++){
            HSBColor col = new HSBColor((mainHSB.h + (i * (1/(float)colorsNum))) % 1, mainHSB.s, mainHSB.b, mainHSB.a);
            colors.Add(HSBColor.ToColor(col));
        }

        return colors;
    }
	// Use this for initialization
	void Start () {
		HSBColor color;
		color = new HSBColor(Random.Range(0.0f, 1.0f), 1f, 1f);
		Color col;
		col =color.ToColor();		

		foreach (Renderer r in transform.GetComponentsInChildren<Renderer>())
		{			
			r.material.color = col;
		}

	}
Exemple #13
0
    public static HSBColor FromColor(Color color)
    {
        HSBColor ret = new HSBColor(0f, 0f, 0f, color.a);

        float r = color.r;
        float g = color.g;
        float b = color.b;

        float max = Mathf.Max(r, Mathf.Max(g, b));

        if (max <= 0)
        {
            return ret;
        }

        float min = Mathf.Min(r, Mathf.Min(g, b));
        float dif = max - min;

        if (max > min)
        {
            if (g == max)
            {
                ret.h = (b - r) / dif * 60f + 120f;
            }
            else if (b == max)
            {
                ret.h = (r - g) / dif * 60f + 240f;
            }
            else if (b > g)
            {
                ret.h = (g - b) / dif * 60f + 360f;
            }
            else
            {
                ret.h = (g - b) / dif * 60f;
            }
            if (ret.h < 0)
            {
                ret.h = ret.h + 360f;
            }
        }
        else
        {
            ret.h = 0;
        }

        ret.h *= 1f / 360f;
        ret.s = (dif / max) * 1f;
        ret.b = max;

        return ret;
    }
Exemple #14
0
    public void UpdateCustomerNumber()
    {
        customerNumberLabel.text = zoneModel.customers.Count.ToString();
        float transparency = .3f;
        HSBColor red = new HSBColor(new Color(1f,0f,0f,transparency));
        HSBColor green = new HSBColor(new Color(0f,1f,0f,transparency));

        icon.color = HSBColor.ToColor( HSBColor.Lerp(green, red, (float)zoneModel.customers.Count / zoneModel.maxQueue));
        progressIndicator.color = icon.color;

        progressIndicator.fillAmount = 0f;
        //icon.color = Color.Lerp(Color.green, Color.red, (float) zone.customers.Count / zone.maxQueue );
    }
    public static Color RGBCircle(Color c, string label, Texture2D colorCircle)
    {
        var r = GUILayoutUtility.GetAspectRect(1);
        r.height = r.width -= 15;
        var r2 = new Rect(r.x + r.width + 5, r.y, 10, r.height);
        var hsb = new HSBColor(c);//It is much easier to work with HSB colours in this case


        var cp = new Vector2(r.x + r.width / 2, r.y + r.height / 2);

        if (Input.GetMouseButton(0))
        {
            var InputVector = Vector2.zero;
            InputVector.x = cp.x - Event.current.mousePosition.x;
            InputVector.y = cp.y - Event.current.mousePosition.y;

            var hyp = Mathf.Sqrt((InputVector.x * InputVector.x) + (InputVector.y * InputVector.y));
            if (hyp <= r.width / 2 + 5)
            {
                hyp = Mathf.Clamp(hyp, 0, r.width / 2);
                float a = Vector3.Angle(new Vector3(-1, 0, 0), InputVector);

                if (InputVector.y < 0)
                {
                    a = 360 - a;
                }

                hsb.h = a / 360;
                hsb.s = hyp / (r.width / 2);
            }
        }

        var hsb2 = new HSBColor(c);
        hsb2.b = 1;
        var c2 = hsb2.ToColor();
        GUI.color = c2;
        hsb.b = GUI.VerticalSlider(r2, hsb.b, 1.0f, 0.0f, "BWSlider", "verticalsliderthumb");

        GUI.color = Color.white * hsb.b;
        GUI.color = new Color(GUI.color.r, GUI.color.g, GUI.color.b, 1);
        GUI.Box(r, colorCircle, GUIStyle.none);

        var pos = (new Vector2(Mathf.Cos(hsb.h * 360 * Mathf.Deg2Rad), -Mathf.Sin(hsb.h * 360 * Mathf.Deg2Rad)) * r.width * hsb.s / 2);

        GUI.color = c;
        GUI.Box(new Rect(pos.x - 5 + cp.x, pos.y - 5 + cp.y, 10, 10), "", "ColorcirclePicker");
        GUI.color = Color.white;

        c = hsb.ToColor();
        return c;
    }
Exemple #16
0
    public Color AddColor(Color c)
    {
        HSBColor tmpColor = new HSBColor(c);
        HSBColor waterColor = new HSBColor(gameObject.renderer.material.GetColor ("_horizonColor"));
        colorStack.Push (waterColor);
        counter++;
        HSBColor newWaterColor = HSBColor.Lerp (waterColor, tmpColor, 0.5f);

        gameObject.renderer.material.SetColor ("_horizonColor", HSBColor.ToColor (newWaterColor));

        return HSBColor.ToColor (newWaterColor);

        //gameObject.renderer.material.SetColor (new Color((c.r+waterColor.r)*0.5,(c.r+waterColor.g)*0.5,(c.r+waterColor.b)*0.5),0);
    }
    void setTraits()
    {
        float    org_x  = this.transform.position.x;
        float    org_y  = this.transform.position.y;
        HSBColor orgcol = new HSBColor(this.renderer.material.color);

        //orgcol.s = ((org_y + 14.0f)/28.0f);
        orgcol.s = 1.0f;
        orgcol.b = 1.0f;
        orgcol.h = ((org_x + 15.0f) / 40.0f);
        this.renderer.material.color = HSBColor.ToColor(orgcol);

        this.transform.localScale = new Vector3(((org_y + 12.0f) / 40.0f), ((org_y + 12.0f) / 40.0f), this.transform.localScale.z);
    }
Exemple #18
0
 void Update()
 {
     if (isUI)
     {
         image.material.SetColor("_Color", HSBColor.ToColor(new HSBColor(Mathf.PingPong(Time.time * Speed, 1), 1, 1)));
     }
     else
     {
         foreach (Renderer r in rend)
         {
             r.material.SetColor("_Color", HSBColor.ToColor(new HSBColor(Mathf.PingPong(Time.time * Speed, 1), 1, 1)));
         }
     }
 }
Exemple #19
0
        public override void Apply()
        {
            //var f = MathHelper.SmoothStep(0, 1, (float)durationCurrent / StepCountTotal);
            var f = DurationCurrent / Duration;

            hsbValueCurrent = HSBColor.Lerp(hsbValueBegin, hsbValueEnd, f);

            ValueCurrent = hsbValueCurrent.ToColor();

            foreach (var material in Materials)
            {
                material.color = ValueCurrent;
            }
        }
Exemple #20
0
    void FixedUpdate()
    {
        float time = Time.time;

        //Color32 textColor32 = new Color32(
        //(byte)Mathf.Abs(255 * Mathf.Sin(time)),        // R
        //(byte)Mathf.Abs(255 * Mathf.Sin(time)),        // G
        //(byte)Mathf.Abs(255 * Mathf.Sin(time)),        // B
        //(byte)255);                                    // A

        Color color = HSBColor.ToColor(new HSBColor(Mathf.PingPong(Time.time * Speed, 1), 1, 1));

        gameTitleText.color = color;
    }
Exemple #21
0
    private void UpdateColor(Color color)
    {
        Color = color;

        // Remove this to reduce garbage.
        Hex = ColorToHex(Color);

        HSBColor hsbColor = new HSBColor(color);

        H = hsbColor.h;
        S = hsbColor.s;
        B = hsbColor.b;

        SelectedColor.Color = Color;
    }
Exemple #22
0
        /// <summary>
        /// Constructor
        /// </summary>
        public LightOverviewControl()
        {
            this.InitializeComponent();

            var stops = 7;
            var step  = Light.MaxHue / stops;

            for (int i = 0; i < stops; i++)
            {
                var gs = new GradientStop();
                gs.Offset = (float)i / stops;
                gs.Color  = HSBColor.FromHSB(i * step, 100, 255);
                HueGradient.GradientStops.Add(gs);
            }
        }
    public void Reset()
    {
        reseting = true;
        HSBColor hsb = HSBColor.FromColor(Color);

        H         = hsb.h;
        S         = hsb.s;
        B         = hsb.b;
        img.color = Color;
        transform.GetChild(0).GetComponent <Slider>().value = H;
        transform.GetChild(1).GetComponent <Slider>().value = S;
        transform.GetChild(2).GetComponent <Slider>().value = B;
        createTexture(H);
        reseting = false;
    }
        public void Update()
        {
            if (!EnergyBar)
            {
                return;
            }

            if (Config.RainbowOnFullEnergy)
            {
                if (Modifiers.instaFail || (EnergyCounter.energy == 1 && Modifiers.energyType == GameplayModifiers.EnergyType.Bar))
                {
                    EnergyBar.color = HSBColor.ToColor(new HSBColor(Mathf.PingPong(Time.time * 0.5f, 1), 1, 1));
                }
            }
        }
        // Update is called once per frame
        public override void Update()
        {
            base.Update();

            if (Entity == null)
            {
                return;
            }

            if (HealthBar != null)
            {
                HealthBar.fillAmount = Entity.Status.DurabilityInPercent * 0.01f;
                HealthBar.color      = HSBColor.ToColor(HSBColor.Lerp(Color.red, Color.green, HealthBar.fillAmount));
            }
        }
Exemple #26
0
        public void SetColors(Color def, Color?selected = null, Color?abandoned = null)
        {
            Color s = (selected == null)
                                ? Color.red
                                : (Color)selected;

            Color a = (abandoned == null)
                                ? HSBColor.Lerp(HSBColor.FromColor(def), HSBColor.Black, 0.67f).ToColor()
                                : (Color)abandoned;

            AddColor("default", def);
            AddColor("selected", s);
            AddColor("abandoned", a);
            SetColor("default");
        }
Exemple #27
0
 public void init() // all instances will be prepared
 {
     Text             = "MandelBrot";
     HSBcol           = new HSBColor();
     panel2.BackColor = Color.FromArgb(95, Color.Black);
     x1       = 640;
     y1       = 480;
     finished = false;
     c1       = Cursors.WaitCursor;
     c2       = Cursors.Cross;
     xy       = (float)x1 / (float)y1;
     picture  = new Bitmap(x1, y1);
     g1       = Graphics.FromImage(picture);
     finished = true;
 }
Exemple #28
0
 private void Update()
 {
     background.GetComponent <Renderer>().material.SetColor("_Color", HSBColor.ToColor(new HSBColor(Mathf.PingPong(Time.time * 0.1f, 1), 0.4f, 1)));
     if (Input.GetKeyDown(KeyCode.K))
     {
         ToggleParty(true);
         GameObject.Find("confettiR").GetComponent <ParticleSystem>().Play();
         GameObject.Find("confettiL").GetComponent <ParticleSystem>().Play();
     }
     if (spinner && !spawnedSpinner)
     {
         StartCoroutine(SpawnSpinner());
     }
     Debug.Log(spinner);
 }
    void CreateLanes()
    {
        lanes = new List<Lane>(numberOfLanes);

        for (int i = 0; i < numberOfLanes; i++) {
            var lane = Instantiate(lanePrefab, Vector3.zero, Quaternion.identity) as Lane;
            //lane.GetComponent<tk2dSprite>().color = lerpPoints.GetRangeValue((float)i/(float)numberOfLanes);
            float h = Mathf.Lerp(hueBottom, hueTop, (float)i / (float)numberOfLanes);
            var hsb = new HSBColor(0.6f, h, 1.0f, 0.3f);
            lane.GetComponent<tk2dSprite>().color = hsb.ToColor();
            lane.transform.parent = transform;
            lane.transform.localPosition = new Vector3(0, i * laneDistance, i * zLaneDistance);
            lanes.Add(lane);
        }
    }
 public IEnumerator HueTransition()
 {
     running = true;
     HSB = new HSBColor (Color.red);
     HSB.h = 0;
     float emissionHue = 0f;
     while (activated) {
         emissionHue = Mathf.PingPong (Time.time, 1f);
         HSB.h = emissionHue;
         Color colour = HSBColor.ToColor(HSB);
         rend.material.SetColor ("_EmissionColor", colour);
         yield return new WaitForEndOfFrame();
     }
     running = false;
 }
        void Update()
        {
            try
            {
                if (playerNameText != null)
                {
                    if (Config.Instance.SpectatorMode)
                    {
                        if (IPA.Loader.PluginManager.AllPlugins.Select(x => x.Metadata.Name) //BSIPA Plugins
                            .Concat(IPA.Loader.PluginManager.Plugins.Select(x => x.Name))    //Old IPA Plugins
                            .Any(x => x == "CameraPlus") && (camera == null || !camera.isActiveAndEnabled))
                        {
                            camera = FindObjectsOfType <Camera>().FirstOrDefault(x => (x.name.StartsWith("CamPlus_") || x.name.Contains("cameraplus")) && x.isActiveAndEnabled);
                        }

                        if (camera != null)
                        {
                            playerNameText.rectTransform.rotation    = Quaternion.LookRotation(playerNameText.rectTransform.position - camera.transform.position);
                            playerSpeakerIcon.rectTransform.rotation = Quaternion.LookRotation(playerSpeakerIcon.rectTransform.position - camera.transform.position);
                        }
                        else
                        {
                            playerNameText.rectTransform.rotation    = Quaternion.LookRotation(playerNameText.rectTransform.position - CustomAvatar.Plugin.Instance.PlayerAvatarManager._playerAvatarInput.HeadPosRot.Position);
                            playerSpeakerIcon.rectTransform.rotation = Quaternion.LookRotation(playerSpeakerIcon.rectTransform.position - CustomAvatar.Plugin.Instance.PlayerAvatarManager._playerAvatarInput.HeadPosRot.Position);
                        }
                    }
                    else
                    {
                        playerNameText.rectTransform.rotation    = Quaternion.LookRotation(playerNameText.rectTransform.position - CustomAvatar.Plugin.Instance.PlayerAvatarManager._playerAvatarInput.HeadPosRot.Position);
                        playerSpeakerIcon.rectTransform.rotation = Quaternion.LookRotation(playerSpeakerIcon.rectTransform.position - CustomAvatar.Plugin.Instance.PlayerAvatarManager._playerAvatarInput.HeadPosRot.Position);
                    }

                    if (rainbowName)
                    {
                        playerNameText.color = HSBColor.ToColor(nameColor);
                        nameColor.h         += 0.125f * Time.deltaTime;
                        if (nameColor.h >= 1f)
                        {
                            nameColor.h = 0f;
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Plugin.log.Warn($"Unable to rotate text to the camera! Exception: {e}");
            }
        }
Exemple #32
0
    public static void FromColor(Color color, ref HSBColor ret)
    {
        float r = color.r;
        float g = color.g;
        float b = color.b;

        float max = Mathf.Max(r, Mathf.Max(g, b));

        if (max <= 0)
        {
            return;
        }

        float min = Mathf.Min(r, Mathf.Min(g, b));
        float dif = max - min;

        if (max > min)
        {
            if (g == max)
            {
                ret.h = (b - r) / dif * 60f + 120f;
            }
            else if (b == max)
            {
                ret.h = (r - g) / dif * 60f + 240f;
            }
            else if (b > g)
            {
                ret.h = (g - b) / dif * 60f + 360f;
            }
            else
            {
                ret.h = (g - b) / dif * 60f;
            }
            if (ret.h < 0)
            {
                ret.h = ret.h + 360f;
            }
        }
        else
        {
            ret.h = 0;
        }

        ret.h *= 1f / 360f;
        ret.s  = (dif / max) * 1f;
        ret.b  = max;
    }
Exemple #33
0
        public DeepBlueThemeTemplate() : base()
        {
            Name          = "deep blue";
            IsSystemTheme = true;
            BannerImage   = "/Assets/Themes/Blue.png";

            DefaultColorList.Add(HSBColor.FromColor(Color.FromArgb(0xff, 0x0d, 0x7e, 0xff)));
            DefaultColorList.Add(HSBColor.FromColor(Color.FromArgb(0xff, 0x0b, 0x74, 0xe9)));
            DefaultColorList.Add(HSBColor.FromColor(Color.FromArgb(0xff, 0x0a, 0x65, 0xcc)));
            DefaultColorList.Add(HSBColor.FromColor(Color.FromArgb(0xff, 0x09, 0x58, 0xb3)));

            foreach (var color in DefaultColorList)
            {
                ColorList.Add(color.Clone());
            }
        }
Exemple #34
0
    public static HSBColor Lerp(HSBColor a, HSBColor b, float t)
    {
        // works around bug with LerpAngle
        float angle = Mathf.LerpAngle(a.h * 360f, b.h * 360f, t);

        while (angle < 0f)
        {
            angle += 360f;
        }
        while (angle > 360f)
        {
            angle -= 360f;
        }

        return(new HSBColor(angle / 360f, Mathf.Lerp(a.s, b.s, t), Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t)));
    }
    void UpdateColor(Color color)
    {
        if (_cachedMode != mode ||
            _cachedColor != color)
        {
            _hsb         = new HSBColor(color);
            _cachedMode  = mode;
            _cachedColor = color;

            DrawMain();
            DrawSidebar();

            mainTexture.Apply();
            sidebarTexture.Apply();
        }
    }
Exemple #36
0
    public void RandomiseOffsetColours(GrandData final)
    {
        Color skin = final.Info.C_Skin;

        HSBColor offtemp = new HSBColor(skin);

        //offtemp.h += (Random.value - Random.value)/50;
        //offtemp.s += (Random.value)/10;
        //offtemp.b += Random.Range(-0.05F, 0.02F);
        final.Info.C_Offset = offtemp.ToColor();

        HSBColor nosetemp = new HSBColor(skin);

        nosetemp.s       *= 1.6F;
        final.Info.C_Nose = nosetemp.ToColor();
    }
Exemple #37
0
        internal void Initialize(ElevenConfig gameConfig, GamePreviewItem preview, Color color)
        {
            this.gameConfig  = gameConfig;
            this.previewItem = preview;
            titleText.text   = gameConfig.gameName;

            foreach (var image in images)
            {
                HSBColor hsbColor = new HSBColor(color);
                hsbColor.brightness = image.brightness;
                hsbColor.alpha      = image.alpha;
                image.image.color   = hsbColor.ToColor();
            }

            button.onClick.AddListener(PlayGame);
        }
    void Update()
    {
        HSBColor hsb  = new HSBColor(currentColor);
        float    newH = hsb.h + oscillationSpeed * Utilities.unscaledDeltaTime;

        if (newH > 1)
        {
            newH = 0;
        }
        if (newH < 0)
        {
            newH = 1;
        }
        hsb.h        = newH;
        currentColor = hsb.ToColor();
    }
        private void Update()
        {
            if (!canBeUsed)
            {
                return;
            }

            // The performance impact of this is unmeasured but probably negligable. I do want to find a way to do this without using Update()
            if (Config.UseFadeDisplayType)
            {
                BarComponents[0].color = HSBColor.Lerp(
                    HSBColor.FromColor(Config.StartColor),
                    HSBColor.FromColor(Config.EndColor),
                    SyncController.songTime / SyncController.songLength).ToColor();
            }
        }
Exemple #40
0
    // Use this for initialization
    void Start()
    {
        HSBColor color;

        color = new HSBColor(Random.Range(0.0f, 1.0f), 1f, 1f);
        Color col;

        col = color.ToColor();
        //this.gameObject.renderer.material.color = col;

        foreach (Renderer r in transform.GetComponentsInChildren <Renderer>())
        {
            Debug.Log("foo");
            r.material.color = col;
        }
    }
        public PureThemeTemplate()
            : base()
        {
            Name          = "arctic";
            IsSystemTheme = true;
            BannerImage   = "/Assets/Themes/Pure.png";

            DefaultColorList.Add(HSBColor.FromColor(Color.FromArgb(0xff, 0x6d, 0xd0, 0xf7)));
            DefaultColorList.Add(HSBColor.FromColor(Color.FromArgb(0xff, 0xaa, 0xe0, 0xf5)));
            DefaultColorList.Add(HSBColor.FromColor(Color.FromArgb(0xff, 0xdb, 0xec, 0xf2)));

            foreach (var color in DefaultColorList)
            {
                ColorList.Add(color.Clone());
            }
        }
    private void setColor(float value, float topThreshold, float botThreshold, float topRange, float botRange)
    {
        var color = lowColor;

        if (value > topThreshold)
        {
            color = HSBColor.Lerp(lowHSB, hightHSB, (value - topThreshold) / topRange).ToColor();
            //color = Color.Lerp(lowColor, hightColor, (value-topThreshold)/topRange);
        }
        else if (value < botThreshold)
        {
            color = HSBColor.Lerp(lowHSB, hightHSB, (value - botThreshold) / botRange).ToColor();
            //color = Color.Lerp(lowColor, hightColor, (value-botThreshold)/botRange);
        }
        GL.Color(color);
    }
 private void Initialize(HSBColor startingColor)
 {
     Hue = new(() =>
     {
         NotifyPropertyChanged(nameof(SampleColor));
         NotifyPropertyChanged("Hue");
     })
     {
         Name     = "Hue",
         MinValue = HSBColor.MinHue,
         MaxValue = HSBColor.MaxHue,
         Value    = startingColor.Hue
     };
     Saturation = new(() =>
     {
         NotifyPropertyChanged(nameof(SampleColor));
         NotifyPropertyChanged("Saturation.Value");
     })
     {
         Name     = "Saturation",
         MinValue = HSBColor.MinSaturation,
         MaxValue = HSBColor.MaxSaturation,
         Value    = startingColor.Saturation
     };
     Brightness = new(() =>
     {
         NotifyPropertyChanged(nameof(SampleColor));
         NotifyPropertyChanged(nameof(Brightness));
     })
     {
         Name     = "Brightness",
         MinValue = HSBColor.MinBrightness,
         MaxValue = HSBColor.MaxBrightness,
         Value    = startingColor.Brightness
     };
     Opacity = new(() =>
     {
         NotifyPropertyChanged(nameof(SampleColor));
         NotifyPropertyChanged(nameof(Opacity));
     })
     {
         Name     = "Opacity",
         MinValue = HSBColor.MinOpacity,
         MaxValue = HSBColor.MaxOpacity,
         Value    = startingColor.Opacity
     };
 }
Exemple #44
0
    /// <summary>
    ///     Given a time measurement <paramref name="t" />, return a colour that is linearly
    ///     interpolated between the colours <paramref name="a" /> and <paramref name="b" />, based on a function at the
    ///     parameterized time <paramref name="t" />.
    /// </summary>
    /// <param name="a">The first colour to interpolate between.</param>
    /// <param name="b">The second colour to interpolate between.</param>
    /// <param name="t">The time variable used to interpolate between the colours.</param>
    /// <returns>The interpolated <see cref="HSBColor" /> colour.</returns>
    public static HSBColor Lerp(HSBColor a, HSBColor b, float t)
    {
        float h, s;

        // check special case black (color.b==0): interpolate neither hue nor saturation! check
        // special case grey (color.s==0): don't interpolate hue!
        if (a.b == 0)
        {
            h = b.h;
            s = b.s;
        }
        else if (b.b == 0)
        {
            h = a.h;
            s = a.s;
        }
        else
        {
            if (a.s == 0)
            {
                h = b.h;
            }
            else if (b.s == 0)
            {
                h = a.h;
            }
            else
            {
                float angle = Mathf.LerpAngle(a.h * 360f, b.h * 360f, t);
                while (angle < 0f)
                {
                    angle += 360f;
                }

                while (angle > 360f)
                {
                    angle -= 360f;
                }

                h = angle / 360f;
            }

            s = Mathf.Lerp(a.s, b.s, t);
        }

        return(new HSBColor(h, s, Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t)));
    }
Exemple #45
0
    // Token: 0x0600002B RID: 43 RVA: 0x00002C54 File Offset: 0x00001054
    public static HSBColor FromColor(Color color)
    {
        HSBColor result = new HSBColor(0f, 0f, 0f, color.a);
        float    r      = color.r;
        float    g      = color.g;
        float    num    = color.b;
        float    num2   = Mathf.Max(r, Mathf.Max(g, num));

        if (num2 <= 0f)
        {
            return(result);
        }
        float num3 = Mathf.Min(r, Mathf.Min(g, num));
        float num4 = num2 - num3;

        if (num2 > num3)
        {
            if (g == num2)
            {
                result.h = (num - r) / num4 * 60f + 120f;
            }
            else if (num == num2)
            {
                result.h = (r - g) / num4 * 60f + 240f;
            }
            else if (num > g)
            {
                result.h = (g - num) / num4 * 60f + 360f;
            }
            else
            {
                result.h = (g - num) / num4 * 60f;
            }
            if (result.h < 0f)
            {
                result.h += 360f;
            }
        }
        else
        {
            result.h = 0f;
        }
        result.h *= 0.00277777785f;
        result.s  = num4 / num2 * 1f;
        result.b  = num2;
        return(result);
    }
Exemple #46
0
    public static HSBColor FromColor(Color color)
    {
        HSBColor result = new HSBColor(0f, 0f, 0f, color.a);
        float    r      = color.r;
        float    g      = color.g;
        float    b      = color.b;
        float    num    = Mathf.Max(r, Mathf.Max(g, b));

        if (num <= 0f)
        {
            return(result);
        }
        float num2 = Mathf.Min(r, Mathf.Min(g, b));
        float num3 = num - num2;

        if (num > num2)
        {
            if (g == num)
            {
                result.H = (b - r) / num3 * 60f + 120f;
            }
            else if (b == num)
            {
                result.H = (r - g) / num3 * 60f + 240f;
            }
            else if (b > g)
            {
                result.H = (g - b) / num3 * 60f + 360f;
            }
            else
            {
                result.H = (g - b) / num3 * 60f;
            }
            if (result.H < 0f)
            {
                result.H += 360f;
            }
        }
        else
        {
            result.H = 0f;
        }
        result.H *= 0.00277777785f;
        result.S  = num3 / num * 1f;
        result.B  = num;
        return(result);
    }
Exemple #47
0
    Color32 GetFaceColor(int aFace)
    {
        //Color32 color = new Color32( (byte)(Random.Range(0,255)), (byte)(Random.Range(0,255)), (byte)(Random.Range(0,255)), 255 );


        HSBColor baseColor = new HSBColor(new Color(243.0f / 255.0f, 225 / 255.0f, 93.0f / 255.0f));

        int numSteps = 2;

        baseColor.h += Random.Range(0, numSteps) / (float)(numSteps);         // + Random.Range (-0.05f,0.05f);
        baseColor.s  = Random.Range(0, 3) == 0 ? Random.Range(0.2f, 0.4f) : Random.Range(0.75f, 0.9f);
        baseColor.b  = Random.Range(0, 5) == 0 ? Random.Range(0.2f, 0.4f) : Random.Range(0.8f, 1.0f);

        Color32 finalColor = baseColor.ToColor();

        return(finalColor);
    }
Exemple #48
0
    // Update is called once per frame
    void FixedUpdate()
    {
        float hueColor = 0.99f;

        if (Random.Range(0, 3) == 1)
        {
            hueColor = 0.07f;
        }

        //Debug.Log("HUECOLOR " + hueColor);
        HSBColor newColor = new HSBColor(hueColor, saturation, brightness, alpha);

        foreach (Material mat in materialsToChange)
        {
            mat.color = newColor.ToColor();
        }
    }
Exemple #49
0
    private void OnEnable()
    {
      HSBColor hsbColor = new HSBColor();
      hsbColor.h = UnityEngine.Random.value;
      hsbColor.s = 1.0f;
      hsbColor.b = 1.0f;

      Color color = hsbColor.ToColor();
      color.a = 1.0f;

      Light light = gameObject.GetComponent<Light>();
      light.color = color;

      SpriteRenderer spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
      spriteRenderer.color = color;

      sun = GameObject.FindObjectOfType<Sun>();
    }
Exemple #50
0
    void GenerateCubes()
    {
        Vector3 cubePos = Camera.main.ScreenToWorldPoint( new Vector3( Input.mousePosition.x, Input.mousePosition.y, 110 ));
        cubePos.z = 10;

        GameObject newCube = (GameObject)Instantiate( cube, cubePos, Quaternion.identity );
        GameObject newCube2 = (GameObject)Instantiate( cube, cubePos, Quaternion.identity );
        GameObject newCube3 = (GameObject)Instantiate( cube, cubePos, Quaternion.identity );
        GameObject newCube4 = (GameObject)Instantiate( cube, cubePos, Quaternion.identity );
        //GameObject newCube5 = (GameObject)Instantiate( cube, cubePos, Quaternion.identity );
        //GameObject newCube6 = (GameObject)Instantiate( cube, cubePos, Quaternion.identity );

        // Change based on HSB
        HSBColor newColor = new HSBColor( currentHue, currentSaturation, currentBrightness );

        newCube.renderer.material.color = HSBColor.ToColor( newColor );
        newCube2.renderer.material.color = HSBColor.ToColor( newColor );
        newCube3.renderer.material.color = HSBColor.ToColor( newColor );
        newCube4.renderer.material.color = HSBColor.ToColor( newColor );
        //newCube5.renderer.material.color = HSBColor.ToColor( newColor );
        //newCube6.renderer.material.color = HSBColor.ToColor( newColor );

        Debug.Log( newColor );
    }
        public static HSBColor FromColor(Color rgbColor)
        {
            HSBColor result = new HSBColor();

            // preserve alpha
            result.A = rgbColor.A;

            // convert R, G, B to numbers from 0 to 1
            double r = rgbColor.R / 255d;
            double g = rgbColor.G / 255d;
            double b = rgbColor.B / 255d;

            double max = Math.Max(r, Math.Max(g, b));
            double min = Math.Min(r, Math.Min(g, b));

            // hue
            if (max == min)
                result.H = 0;
            else if (max == r)
                result.H = (60 * (g - b) / (max - min) + 360) % 360;
            else if (max == g)
                result.H = 60 * (b - r) / (max - min) + 120;
            else
                result.H = 60 * (r - g) / (max - min) + 240;

            // saturation
            if (max == 0)
                result.S = 0;
            else
                result.S = 1 - min / max;

            // brightness
            result.B = max;

            return result;
        }
Exemple #52
0
    /// <summary>
    /// Convert an <see cref="HSBColor" /> value to an equivalent <see cref="Color" /> value.
    /// </summary>
    /// <remarks>
    /// This method is based on code from http://www.cs.rit.edu/~ncs/color/ by Eugene Vishnevsky.
    /// </remarks>
    /// <param name="hsbColor">The <see cref="HSBColor" /> struct to be converted</param>
    /// <returns>An equivalent <see cref="Color" /> struct, compatible with the GDI+ library</returns>
    public static Color ToRGB(HSBColor hsbColor)
    {
        Color rgbColor = Colors.Black;

        // Determine which sector of the color wheel contains this hue
        // hsbColor.H ranges from 0 to 255, and there are 6 sectors, so 42.5 per sector
        int sector = (int)Math.Floor((double)hsbColor.H / 42.5);
        // Calculate where the hue lies within the sector for interpolation purpose
        double fraction = (double)hsbColor.H / 42.5 - (double)sector;

        double sFrac = (double)hsbColor.S / 255.0;
        byte p = (byte)(((double)hsbColor.B * (1.0 - sFrac)) + 0.5);
        byte q = (byte)(((double)hsbColor.B * (1.0 - sFrac * fraction)) + 0.5);
        byte t = (byte)(((double)hsbColor.B * (1.0 - sFrac * (1.0 - fraction))) + 0.5);


        switch (sector)
        {
            case 0:			// red - yellow
                rgbColor = Color.FromArgb(hsbColor.A, hsbColor.B, t, p);
                break;
            case 1:			// yellow - green
                rgbColor = Color.FromArgb(hsbColor.A, q, hsbColor.B, p);
                break;
            case 2:			// green - cyan
                rgbColor = Color.FromArgb(hsbColor.A, p, hsbColor.B, t);
                break;
            case 3:			// cyan - blue
                rgbColor = Color.FromArgb(hsbColor.A, p, q, hsbColor.B);
                break;
            case 4:			// blue - magenta
                rgbColor = Color.FromArgb(hsbColor.A, t, p, hsbColor.B);
                break;
            case 5:
            default:		// magenta - red
                rgbColor = Color.FromArgb(hsbColor.A, hsbColor.B, p, q);
                break;
        }

        return rgbColor;
    }
Exemple #53
0
 public static void Test()
 {
     HSBColor color;
    
     color = new HSBColor(Color.red);
     Debug.Log("red: " + color);
    
     color = new HSBColor(Color.green);
     Debug.Log("green: " + color);
    
     color = new HSBColor(Color.blue);
     Debug.Log("blue: " + color);
    
     color = new HSBColor(Color.grey);
     Debug.Log("grey: " + color);
    
     color = new HSBColor(Color.white);
     Debug.Log("white: " + color);
    
     color = new HSBColor(new Color(0.4f, 1f, 0.84f, 1f));
     Debug.Log("0.4, 1f, 0.84: " + color);
    
     Debug.Log("164,82,84   .... 0.643137f, 0.321568f, 0.329411f  :" + ToColor(new HSBColor(new Color(0.643137f, 0.321568f, 0.329411f))));
 }
Exemple #54
0
    public static HSBColor Lerp(HSBColor a, HSBColor b, float t)
    {
        float h,s;

        //check special case black (color.b==0): interpolate neither hue nor saturation!
        //check special case grey (color.s==0): don't interpolate hue!
        if(a.b==0){
            h=b.h;
            s=b.s;
        }else if(b.b==0){
            h=a.h;
            s=a.s;
        }else{
            if(a.s==0){
                h=b.h;
            }else if(b.s==0){
                h=a.h;
            }else{
                // works around bug with LerpAngle
                float angle = Mathf.LerpAngle(a.h * 360f, b.h * 360f, t);
                while (angle < 0f)
                    angle += 360f;
                while (angle > 360f)
                    angle -= 360f;
                h=angle/360f;
            }
            s=Mathf.Lerp(a.s,b.s,t);
        }
        return new HSBColor(h, s, Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t));
    }
Exemple #55
0
		protected void SetColor(Color color)
		{
			myColor = color;
			myColor.a = 1f;
			hsbColor = HSBColor.FromColor(myColor);
			HueSlider.Value = hsbColor.h;
			SaturationSlider.Value = hsbColor.s;
			ValueSlider.Value = hsbColor.b;

			colorMaterial.color = myColor;
			VoxUserScript.NewBlockColor = myColor;
		}
 public static Color FromHSB(HSBColor hsbColor)
 {
     float r = hsbColor.b;
     float g = hsbColor.b;
     float b = hsbColor.b;
     if (hsbColor.s != 0)
     {
         float max = hsbColor.b;
         float dif = hsbColor.b * hsbColor.s / 255f;
         float min = hsbColor.b - dif;
         float h = hsbColor.h * 360f / 255f;
         if (h < 60f)
         {
             r = max;
             g = h * dif / 60f + min;
             b = min;
         }
         else if (h < 120f)
         {
             r = -(h - 120f) * dif / 60f + min;
             g = max;
             b = min;
         }
         else if (h < 180f)
         {
             r = min;
             g = max;
             b = (h - 120f) * dif / 60f + min;
         }
         else if (h < 240f)
         {
             r = min;
             g = -(h - 240f) * dif / 60f + min;
             b = max;
         }
         else if (h < 300f)
         {
             r = (h - 240f) * dif / 60f + min;
             g = min;
             b = max;
         }
         else if (h <= 360f)
         {
             r = max;
             g = min;
             b = -(h - 360f) * dif / 60 + min;
         }
         else
         {
             r = 0;
             g = 0;
             b = 0;
         }
     }
     return Color.FromArgb
         (
             hsbColor.a,
             (int)Math.Round(Math.Min(Math.Max(r, 0), 255)),
             (int)Math.Round(Math.Min(Math.Max(g, 0), 255)),
             (int)Math.Round(Math.Min(Math.Max(b, 0), 255))
             );
 }
Exemple #57
0
    public static HSBColor Lerp(HSBColor a, HSBColor b, float t)
    {
        // works around bug with LerpAngle
        float angle = Mathf.LerpAngle(a.h * 360f, b.h * 360f, t);
        while (angle < 0f)
            angle += 360f;
        while (angle > 360f)
            angle -= 360f;

        return new HSBColor(angle / 360f, Mathf.Lerp(a.s, b.s, t), Mathf.Lerp(a.b, b.b, t), Mathf.Lerp(a.a, b.a, t));
    }
    void generateMesh(int chunkX, int chunkY)
    {
        List<Vector3> verts = new List<Vector3>();
        List<Color32> cols = new List<Color32>();
        List<Vector2> uvs = new List<Vector2>();
        List<Vector2> uvs2 = new List<Vector2>();
        List<int> tris = new List<int>();

        int t = 0;  // number of tris
        for (int x = 0; x < SIZE; x++) {
            for (int y = 0; y < SIZE; y++) {

                float x1 = x + chunkX * SIZE - HSIZE;
                float y1 = y + chunkY * SIZE - HSIZE;
                float x2 = (x + 1) + chunkX * SIZE - HSIZE;
                float y2 = (y + 1) + chunkY * SIZE - HSIZE;
                x1 *= TRI_SIZE;
                y1 *= TRI_SIZE;
                x2 *= TRI_SIZE;
                y2 *= TRI_SIZE;

                float scale = 10f;
                float mod = 1.0f / 20.0f;
                Vector3 v1 = new Vector3(x1, scale * Mathf.PerlinNoise(x1 * mod + seed, y1 * mod + seed) - scale / 2.0f, y1);
                Vector3 v2 = new Vector3(x1, scale * Mathf.PerlinNoise(x1 * mod + seed, y2 * mod + seed) - scale / 2.0f, y2);
                Vector3 v3 = new Vector3(x2, scale * Mathf.PerlinNoise(x2 * mod + seed, y2 * mod + seed) - scale / 2.0f, y2);
                Vector3 v4 = new Vector3(x2, scale * Mathf.PerlinNoise(x2 * mod + seed, y1 * mod + seed) - scale / 2.0f, y1);

                verts.Add(v1);
                verts.Add(v2);
                verts.Add(v3);
                verts.Add(v3);
                verts.Add(v4);
                verts.Add(v1);

                // main texture uvs
                uvs.Add(new Vector2(0.0f, 0.0f));
                uvs.Add(new Vector2(0.0f, 1.0f));
                uvs.Add(new Vector2(1.0f, 1.0f));
                uvs.Add(new Vector2(1.0f, 1.0f));
                uvs.Add(new Vector2(1.0f, 0.0f));
                uvs.Add(new Vector2(0.0f, 0.0f));

                // noise uvs
                uvs2.Add(new Vector2((float)x / SIZE, (float)y / SIZE));
                uvs2.Add(new Vector2((float)x / SIZE, (float)(y + 1) / SIZE));
                uvs2.Add(new Vector2((float)(x + 1) / SIZE, (float)(y + 1) / SIZE));
                uvs2.Add(new Vector2((float)(x + 1) / SIZE, (float)(y + 1) / SIZE));
                uvs2.Add(new Vector2((float)(x + 1) / SIZE, (float)y / SIZE));
                uvs2.Add(new Vector2((float)x / SIZE, (float)y / SIZE));

                Color col = (chunkX + chunkY) % 2 == 0 ? Color.red : Color.blue;
                col = new HSBColor(Random.value, 1.0f, 1.0f).ToColor();

                for (int i = 0; i < 6; i++) {
                    tris.Add(t++);
                    cols.Add(col);
                }
            }
        }

        GameObject go = new GameObject("Chunk: " + chunkX + " " + chunkY);
        #if UNITY_EDITOR
        go.transform.SetParent(transform, true);
        #endif
        MeshRenderer mr = go.AddComponent<MeshRenderer>();
        MeshCollider mc = go.AddComponent<MeshCollider>();
        mr.material = mat;
        MeshFilter mf = go.AddComponent<MeshFilter>();

        Mesh m = new Mesh();
        m.vertices = verts.ToArray();
        m.colors32 = cols.ToArray();
        m.uv = uvs.ToArray();
        m.uv2 = uvs2.ToArray();
        m.triangles = tris.ToArray();
        m.RecalculateBounds();
        Bounds newb = new Bounds(m.bounds.center, m.bounds.size + Vector3.up * 100.0f);
        m.bounds = newb;
        m.RecalculateNormals();
        mf.mesh = m;
        mc.sharedMesh = m;
        Chunk c = new Chunk();
        c.obj = go;
        c.mesh = m;
        c.x = chunkX;
        c.y = chunkY;
        chunks.Add(c);
    }
Exemple #59
0
    /// <summary>
    /// Convert a <see cref="Color" /> value to an equivalent <see cref="HSBColor" /> value.
    /// </summary>
    /// <remarks>
    /// This method is based on code from http://www.cs.rit.edu/~ncs/color/ by Eugene Vishnevsky.
    /// </remarks>
    /// <param name="rgbColor">The <see cref="Color" /> struct to be converted</param>
    /// <returns>An equivalent <see cref="HSBColor" /> struct</returns>
    public static HSBColor FromRGB(Color rgbColor)
    {
        double r = (double)rgbColor.R / 255.0;
        double g = (double)rgbColor.G / 255.0;
        double b = (double)rgbColor.B / 255.0;

        double min = Math.Min(Math.Min(r, g), b);
        double max = Math.Max(Math.Max(r, g), b);

        HSBColor hsbColor = new HSBColor(rgbColor.A, 0, 0, 0);

        hsbColor.B = (byte)(max * 255.0 + 0.5);

        double delta = max - min;

        if (max != 0.0)
        {
            hsbColor.S = (byte)(delta / max * 255.0 + 0.5);
        }
        else
        {
            hsbColor.S = 0;
            hsbColor.H = 0;
            return hsbColor;
        }

        double h;
        if (r == max)
            h = (g - b) / delta;		// between yellow & magenta
        else if (g == max)
            h = 2 + (b - r) / delta;	// between cyan & yellow
        else
            h = 4 + (r - g) / delta;	// between magenta & cyan

        hsbColor.H = (byte)(h * 42.5);
        if (hsbColor.H < 0)
            hsbColor.H += 255;

        return hsbColor;
    }
Exemple #60
0
 // Use this for initialization
 void Start()
 {
     sprite = GetComponent<tk2dSprite>();
     color = HSBColor.FromColor(sprite.color);
 }